Only show posts if they’re less than 3 days old
-
I would like to add a “breaking news” ticker just under the header on my site’s custom front page. I want it to show only posts less than 3 days old from a specific category.
My thought is to put the entire mini-loop inside a php if clause, compare the post date to a number, and only print the breaking news ticker if it’s less than that number. The idea being if I post something in the “breaking news” category, for the next few days it shows up in a ticker box on the front page. If there aren’t any breaking news posts younger than three days, the ticker doesn’t show up.
I have the mini-loop working beautifully, posting the 6 most recent news posts on a static home page, using this code:
<?php $my_query = new WP_Query('category_name=news&showposts=6'); while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID; ?> <a>"> <?php the_title(); ?> </a> <?php endwhile; ?>
Any thoughts or ideas, or has anyone done something like this before?
- The topic ‘Only show posts if they’re less than 3 days old’ is closed to new replies.