Site logo

Archived topic

Last Modified Date and List my Posts based on Modified Date

11 replies · Started by kunal on November 14, 2018

Viewing posts 1–12 of 12

Hi Guys, quick question. I'm checking the forum, and I see this question has been asked, however, all of the people asking seem to be very technical experienced.

Question: I've activated the Tasty template (premium). And I would like to (a) show the Last Modified stamp on each post and page (2) have my website homepage ordered based on modified date, not just when the post/page was originally published.

Please help!!! thanks!!

Kunal

Also, when I'm in my php editor, in the funtions.php file, it says: "GeneratePress. Please do not make any edits to this file. All edits should be done in a child theme.'

Where the heck is the child theme!!??

Thanks

Actually guys, this is EXACTLY the same question I have. I just want to show the updated date, and if it hasn't been updated, then use the original published date.

https://generatepress.com/forums/topic/post-updated-date/#post-470725

(1) I see the code Tom has provided in that thread. But I have no idea where I would be copy/pasting this code in. I'm checking the page.php file, I can't see where I would paste this in!

(2) and naturally, I want the ordering on my homepage to be updated such that posts are ordered by the modified date (or if not modified, by the originally published date)

Thank you so much!!

Kunal

Hi there,

This is the code for the updated date: https://docs.generatepress.com/article/show-the-updated-post-date/

It can be added using one of these methods: https://docs.generatepress.com/article/adding-css/

As for the second question, you can try this:

add_action( 'pre_get_posts', function( $query ) {
    if ( $query->is_main_query() && ( $query->is_home() || $query->is_search() || $query->is_archive() )  ) {
        $query->set( 'orderby', 'modified' );
        $query->set( 'order', 'desc' );
    }
} );

Which can be added using one of these methods: https://docs.generatepress.com/article/adding-php/

As for a child theme, this should help: https://docs.generatepress.com/article/using-child-theme/

Hi Tom, thanks, would I copy/paste your code:

add_action( 'pre_get_posts', function( $query ) {
    if ( $query->is_main_query() && ( $query->is_home() || $query->is_search() || $query->is_archive() )  ) {
        $query->set( 'orderby', 'modified' );
        $query->set( 'order', 'desc' );
    }
} );

in the function.php file? Because when I go to the functions.php file, it says:
/**
* GeneratePress.
*
* Please do not make any edits to this file. All edits should be done in a child theme.
*
* @package GeneratePress
*/

I'm just curious where I would paste the code you provided?

Tom, TRES AWESOME.

Works!

Thankyou so much!!

K

You're welcome :)

Hi Tom, another quick question. Where do I put the [modified date] tag?

I updated a post, but I want it to show up in under the title of the post. For example, I just tested on one of my pages: http://albertacostandquantitysurveyorguide.com/what-is-a-construction-preliminary-list/

And it says "admin . November 13, 2018"
I would like it to say "admin . last updated December 05, 2018" (for example, since I just updated it today)

Thanks!
Kunal

Give this CSS a shot:

.page-hero time.updated {
    display: inline-block;
}

.page-hero time.updated:before {
    content: "Last updated on ";
}

.page-hero time.updated + .published {
    display: none;
}

Thanks Tom! Works well!!

Kunal

You're welcome :)

This archived topic is closed to new replies.