WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How do I include date on fetch_rss? (7 posts)

  1. WPChina
    Member
    Posted 7 years ago #

    I am fetching an RSS2.0 feed from a wordpress blog and I want to integrate it into my site. I am using pubDate to try to get the date of the feed on my site, but pubDate seems not to work. I can get the title and the URL, but not the date.

    Anyone know how to print the date for posts from the fetched feed? In addition, is it possible to capture other info from that fetched feed when using fetch_rss?

    Tks!

  2. Kafkaesqui

    Posted 7 years ago #

    Try 'pubdate', not 'pubDate'.

  3. WPChina
    Member
    Posted 7 years ago #

    Great, fixed... almost....

    It now prints something like this: "Thu, 16 Nov 2006 01:47:42 +0000"

    But is it possible to only get it to print "Thu, 16 Nov 2006"?

    Thank you Kafkaesqui!

  4. Kafkaesqui

    Posted 7 years ago #

    The simplest way is, since the format is always the same and the character count shouldn't vary, is to parse it using the PHP substr() function.

    Assuming each rss item is held in $item in your code:

    $pubdate = substr($item['pubdate'], 0, 16);

  5. WPChina
    Member
    Posted 7 years ago #

    Sorry to bother you, but I can't figure out where to add that substr. I am using different variations of the following and putting it all different places, but it seems not able to print out the correct info:

    <?php
    require_once(ABSPATH . WPINC . '/rss-functions.php');
    $rss = fetch_rss('http://www.website.com/feed/');
    for($i=0;$i<5;$i++) {
    $item=$rss->items[$i];
    $pubdate=substr($item['pubdate'], 0, 16);
    echo '<p><a href="'.$item['link'].'" title=" '.$item['title'].'">
    <b>'.$item['title'].'</b></a><br><i>'.$item['pubdate'].'</i>
    <br>'.$item['description'].'<a href="'.$item['link'].'">
    more...</a></p>';
    }
    ?>

  6. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    ...<i>'.$item['pubdate'].'</...

    Change that to:
    ...<i>'.$pubdate.'</...

  7. WPChina
    Member
    Posted 7 years ago #

    ahhhhhh.... works well.... tks!

    I will now mark this Resolved!

Topic Closed

This topic has been closed to new replies.

About this Topic