To show post in category in last modified date order, use this code in your category.php or archive.php file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
<?php // Get the current category $category = get_queried_object(); // Custom query to get posts in the current category sorted by last modified date $query_args = array( 'category_name' => $category->slug, 'orderby' => 'modified', // Sort by last modified date 'order' => 'DESC', // Descending order 'posts_per_page' => -1 // Show all posts ); $query = new WP_Query($query_args); // Output the posts if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <p>Last updated: <?php the_modified_date(); ?></p> <?php endwhile; else : echo 'No posts found.'; endif; // Restore original post data wp_reset_postdata(); ?> |