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

  1. WPChina
    Posted 9 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?


  2. Kafkaesqui

    Posted 9 years ago #

    Try 'pubdate', not 'pubDate'.

  3. WPChina
    Posted 9 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 9 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
    Posted 9 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:

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

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

    Change that to:

  7. WPChina
    Posted 9 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