Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have 3 different custom post types, with each type forming my main navigation. When I post something new under one of them, I want that category in the nav to be marked with a "new" label for a limited time (7 days for example).

I've found a few decent posts on how to apply it to single posts, but I can't figure out how to apply it to multiple categories in the top navigation.

The code for single posts is below should that be of any use:

function newly_posted() {
global $post;
$now = date('U'); $published = get_the_time('U');
$new = false;
if( $now-$published  <= 3*24*60*60 ) $new = true;
return $new;
}

Any help would be appreciated!

EDIT: As mentioned in the comments, I'm I'm basically looking for something that will do: If post type X has new post within 7 days, add class "new"

share|improve this question
    
I guess calculating if there is a new post in category on demand would be an intensive task. I suggest you store the time of the last post in each category as an option upon post submit. This way you can have what you need in a matter of one function call. –  Hamed Momeni Apr 7 '13 at 18:22
    
Please post the code that generates the menus. –  s_ha_dum Apr 7 '13 at 18:27
    
The menu code is basically links to pages setup in wordpress, it's nothing special. For example: <li id="nav-design"><a href="<?php echo get_settings('home'); ?>/design"></a></li>` In pseudo code, I'm basically looking for something that will do: If post type X has new post within 7 days, add class "new" –  Tom Apr 8 '13 at 17:21

1 Answer 1

In case anyone else is looking for this in the future, turns out the best way to do it is by using wp_get_recent_posts function. Someone knocked up an example that worked great for me:

<?php $args = array( 'numberposts' => '1' );
$recent_post = wp_get_recent_posts( $args );

if (strtotime($recent_post[0]['post_date']) > strtotime('-7 days'))
    $class = "new!";
?>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.