WordPress.org

Support

Support » How-To and Troubleshooting » Show 'posted date' from Feed on homepage

Show 'posted date' from Feed on homepage

  • adeel.punchlime
    Member

    @adeelpunchlime

    Hi guys, my first post here. On my home page http://www.punchlime.com I have an RSS feed that is bring up the latest 5 blog posts however I now want to add a date when they were posted and have no idea how to do it. The code I am using to get the title is below. I just want to extract the date (not the time) and have no idea how to do that. Any help (and sample code) will be great. Thanks!

    <ul class="separated">
    <?php if ($maxitems == 0) echo '<li>No items.</li>';
    else
    // Loop through each feed item and display each item as a hyperlink.
    foreach ( $rss_items as $item ) : ?>
    <li>
    <a href='<?php echo esc_url( $item->get_permalink() ); ?>'
    title='<?php echo 'Posted '.$item->get_date('j F Y | g:i a'); ?>'>
    <?php echo esc_html( $item->get_title() ); ?></a>
    </li>
Viewing 3 replies - 1 through 3 (of 3 total)
  • adeel.punchlime
    Member

    @adeelpunchlime

    I found a way to do this by adding:
    <?php echo ''.$item->get_date('j F'); echo ' - ' ?>

    However any idea how to show it only as 17 Jan << Instead of 17 January?

    Thanks.

    MD Saiful Islam
    Participant

    @tulihost

    <?php echo ''.$item->get_date('j F'); ?>
    It’s shown only Day and full month name like “07 February”.

    Rajan V
    Member

    @rajanit2000

    <ul class="separated">
    <?php if ($maxitems == 0) echo '<li>No items.</li>';
    else
    // Loop through each feed item and display each item as a hyperlink.
    global $post;
    foreach ( $rss_items as $post ) :
    setup_postdata($post);
     ?>
    <li>
    <a href='<?php echo esc_url( $item->get_permalink() ); ?>'
    title='<?php echo 'Posted '.$item->get_date('j F Y | g:i a'); ?>'>
    <?php echo esc_html( $item->get_title() ); ?></a>
    </li>

    Use this code “setup_postdata() is missing”

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Show 'posted date' from Feed on homepage’ is closed to new replies.