Hacks and Hints TechieVarta

Icon

Another Techie Varta

Wordpress MU: Latest Posts on a single Page

One of the thing I had to decide is the main blog page on my new WordPress Mu site. I decided that I wanted this page to show off latest posts from all the blogs.Using Sitewide Tags was not an option since that does not have a way to import existing posts. I eventually decided to hack my own solution.

Doing this involved some PHP hacking, googling and WPMU Feed plugin. The overall design of the page now uses WPMU Feed to send site-wide post feed. This main page just uses this feed to display posts First download the WPMU Feed plugin and install it. I host feed plugin to http://techievarta.com/feed/.

I cloned my theme to create another copy used by the main site. Than I changed index.php to use the feed. A typical index.php looks like the following:


if there are posts

      show posts;

else

    show error;

endif

The changes required removing else part. So the new index.php looks like”:


if there are posts

     show posts;

endif

<-- Catch the feed and display --->

To catch the feed and display, the code (which is based of feed.php of wordpress installation) looks like the following:


 if ( $rss = fetch_rss( 'http://<site>/feed/',20 ) ) {
       echo '<ul>';
       if ( $num_items !== -1 ) {
          $rss->items = array_slice( $rss->items, 0, $num_items );
       }

       foreach ( (array) $rss->items as $item ) {
          printf('<a href="%1$s" ><h4>%2$s</h4></a><p/>',
             clean_url( $item['link'] ),
             htmlentities( $item['title'] )
             clean_url( $item['link'] ),
             htmlentities( $item['title'] )
          );
         echo "Published ";
         echo $item['pubdate'];
         $dc = $item['dc'];
         if( !empty($dc)){
           echo ' by ';
           echo attribute_escape(  $dc['creator']  );
         }
         echo '<p/>';
         echo attribute_escape(  $item['description']  );
         echo '<p/><br/>';
     }
     echo '</ul>';
 }

Replace <site> with your site’s URL and 20 with number of the contents you want.

Happy Blogging!

Category: Blog Software, WordPress

Tagged: , ,

Leave a Reply