I have a page template that displays a list of posts

I have a page template that displays a list of posts from a custom post type. At the top of the page, I'd like to display the last modified date of the most recent post listed on the page.

Example, I have 3 news articles listed on my page and I want the page template to display the date and time of the most recently modified of the 3 articles.

This code (below) works great on a single news article post.

<?php the_modified_time('F j, Y'); ?> at <?php the_modified_time('g:i a'); ?>

  • hccdev

    it will work on both single.php and page.php, but seems to only work for a single entry. I am looking to pull the most recent last modified time of 3 separate posts and display it above the list of the 3 separate posts.

    My page is News (using news.php as the template).

    In the news.php template is where I want to display the last modified time of 3 posts that are listed on the page (not the last modified time of News)

    News Article 1 has last modified time of June 1, 2013 at 9AM

    News Article 2 has a last modified time of June 1, 2013 at 8:30AM

    News Article 3 has a last modified time of May 31, 2013 at 10PM

    My News page (with template news.php) should display a last modified time of
    News Article 1 because it has last modified time of June 1, 2013 at 9AM (the most recent of the 3 articles).

    Make sense?

  • Mike

    Hi @hccdev

    I see, that makes sense now, although I'm not sure it's going to be possible as the_modified_time() has to be used within the loop on the specific post. Where you want to use it is outside of the loop.

    It might be possible to use get_the_modified_time but you will need a hefty chunk of PHP code to grab all of the last modified dates, compare them and display the most recent.

    Maybe someone else can chime in here but I can't help much as I'm not a PHP coder.

    Cheers,
    Mike

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.