WordPress.org

Ready to get started?Download WordPress

Forums

Show 'posted date' from Feed on homepage (4 posts)

  1. adeel.punchlime
    Member
    Posted 1 year ago #

    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>
  2. adeel.punchlime
    Member
    Posted 1 year ago #

    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.

  3. MD Saiful Islam
    Member
    Posted 1 year ago #

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

  4. Rajan V
    Member
    Posted 1 year ago #

    <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"

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags