The MU forums have moved to WordPress.org

Display multiple RSS feeds on home page? (9 posts)

  1. nick818
    Member
    Posted 17 years ago #

    I looked around, but still couldn't seem to figure out how to do this. I want to be able to display rss feeds from selected blogs on the home page, so it's like a news site with links from different categories (blogs). I tried to use magpie, but it doesn't work, then I read that wordpress already has a function to do this? Anyone know how I can accomplish this? Thanks.

  2. andrea_r
    Moderator
    Posted 17 years ago #

    You have to edit the /wp-admin/index.php file directly.

  3. nick818
    Member
    Posted 17 years ago #

    Not sure I understand. I don't want to display feeds in the dashboard. I want them on the homepage.. the home theme. Do you mean pull the code from the admin index? Can I use this on theme pages?

    <?php
    $rss->items = array_slice($rss->items, 0, 20);
    foreach ($rss->items as $item ) {
    $title = wp_specialchars($item['title']);
    $author = preg_replace( '|(.+?):.+|s', '$1', $item['title'] );
    $post = preg_replace( '|.+?:(.+)|s', '$1', $item['title'] );
    ?>

  4. nick818
    Member
    Posted 17 years ago #

    Or this, I guess?
    <?php
    $rss = @fetch_rss('http://feeds.technorati.com/cosmos/rss/?url='. trailingslashit(get_option('siteurl')) .'&partner=wordpress');
    if ( isset($rss->items) && 0 != count($rss->items) ) {
    ?>

  5. drmike
    Member
    Posted 17 years ago #

    There's two examples of how a RSS is pulled between lines 133 and 168 of the wp-admin/index.php file.

    Hope this helps,
    -drmike

  6. nick818
    Member
    Posted 17 years ago #

    I tried copying 133 through 168 and putting into into the home.php page to see if it would work and it just gave me an error.. "Parse error: parse error, unexpected T_VARIABLE"

  7. andrea_r
    Moderator
    Posted 17 years ago #

    This thread might be helpful, but there's only hints in it, no step by steps. And here's another post with another tip.

    By included, I think whoever mentioned that was referencing the fact that Magpie is already in WP.

  8. nick818
    Member
    Posted 17 years ago #

    Thanks. I think I figured it out with this plugin: http://www.ozpolitics.info/blog/?p=87

  9. iamsgf
    Member
    Posted 15 years ago #

    I used this to get a feed of recent blog posts on my home page if this works for you:

    <?php
    /**************MOST RECENT BLOG POSTS BOCK******************/
    $db_prefix = "wp"; //this is your database prefix, if your first user has wp_1_posts, then your prefix is "wp"
    $howmany = 10; //how many rows of results do you want back?
    $width = 60; //how wide do you want your rows?

    /********************************************************************/

    //i first tried pulling in every blog post by user, but then i lost all information about the default blog address. this became important when a guest
    //user posted on somebody else's blog, at which point i'd find the user's default blog address and contstruct a wrong URL.

    //define('WP_USE_THEMES', true);
    require('./wp-blog-header.php');

    function get_path($userID){
    global $wpdb;
    $req = "select path from wp_blogs where post_parent='" . $userID . "';";
    //echo $req;
    $res = $wpdb->get_results($req);
    $post['path'] = $res[0]->path;
    return $post;
    }

    function bigcmp($a, $b)
    {
    if ($a['datetime'] == $b['datetime']) {
    return 0;
    }
    return ($a['datetime'] < $b['datetime']) ? 1 : -1;
    }

    $request = "select * from wp_blogs;";
    $result = $wpdb->get_results($request);

    //print_r($result);

    $i = 0;

    foreach($result as $v1){

    //get the blog name from each user and save it as $blogname to use in the next foreach
    $db_table = $db_prefix . "_" . $v1->blog_id . "_options" ;
    $requestx = "select option_value from " . $db_table . " where option_name='blogname' and option_id=2;";
    $resultx = $wpdb->get_results($requestx);
    $blogname = $resultx[0]->option_value;

    //for each user get all their posts
    $db_table = $db_prefix . "_" . $v1->blog_id . "_posts" ;
    $request2 = "select * from " . $db_table . ";";
    $result2 = $wpdb->get_results($request2);
    $domain = $v1->domain;
    $path = $v1->path;

    //print_r($result2);

    //list every post in the system
    foreach($result2 as $v2){

    //this part takes the date and breaks it up into year, month, day, but first save the date to use it
    $array = explode(" ", $v2->post_date);
    $array = explode("-", $array[0]);
    $y = $array[0]; $m = $array[1]; $d = $array[2];

    $allposts[$i]['datetime'] = $v2->post_date;

    $string = $y . "/" . $m . "/" . $d . "/" . $v2->post_name;
    $allposts[$i]['title'] = $v2->post_title;
    $allposts[$i]['path'] = $v1->path;

    $post_type = $v2->post_type;

    /*this part gives you the post/page format, and guid URL if it's a guest poster */
    //if guest user ID?
    if($v2->post_type == attachment) {

    }
    else {
    if($v2->guid !== NULL) {
    $allposts[$i]['fullurl'] = $v2->guid;
    $allposts[$i]['blogname'] = $blogname;
    }

    $i++;}
    }

    }

    usort($allposts, "bigcmp");

    //get total number of posts

    $today = date('m-d-Y');
    $totalposts = count($allposts);
    echo '

      ';
      for($i = 0; $i < $totalposts && $i < $howmany; $i++){
      if ($allposts[$i]['post_type'] == attachment)
      {$howmany++;}
      else {
      $dateposred = explode(" ", $allposts[$i]['datetime']);
      $dateposred = explode(":", $dateposred[1]);
      $dateposted = explode(" ", $allposts[$i]['datetime']);
      $dateposted = explode("-", $dateposted[0]);
      $dateposted = $dateposted[2] . "-" . $dateposted[1] . "-" . $dateposted[0] . " o " . $dateposred[0] . ":" . $dateposred[1] . ":" . $dateposred[2];

      //make the length as short as the implementer wants it
      $url = substr($allposts[$i]['title'], 0, $width);
      $author = "Published " . $dateposted;
      $author = substr($author, 0, $width);
      $blogname = $allposts[$i]['blogname'];
      $blogname = substr($blogname, 0, $width);
      $asd = strlen($allposts[$i]['fullurl']);
      $dsa = strlen("");
      if ($dsa !== $asd) {
      echo '

    • <a href="' . $allposts[$i]['fullurl'];
      echo '" title="';
      echo $author;
      echo '">';
      echo $url;
      echo '';
      echo '
    • ';
      }
      else {$howmany++;}
      }
      }
      echo '

    ';
    /*********************MOST RECENT BLOG POSTS END******************************/
    ?>

    you can see it in action at http://megablogs.net

    I hope this helps, cos i spent ages looking for something like that and actually getting it working.

    I am now looking for a piece of code that will allow me to list Most recent members and most recent blogs on my home page. so if you come across something it would be good if you could pass it on to me.

    Thanks

    iamsgf

About this Topic