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 was thinking this would be an easy solution to accomplish, but I'm stuck since Main Pages in the Front-End are arrayed automatically.

Basically I created individual pages to display specific Custom Post Type posts with different Template pages. What I want to accomplish is, if no posts were created for this specific CPT, than the page will not show in the Main Navigation links.

Is this possible? Each page is using a unique URL (i.e. site.com/specials). So if no 'Special' post has been created, I do not want that page to show. Is there a function I can create to accomplish this?

Thanks!

share|improve this question
    
    
Hi s_ha_dum, yes I have tried searching a possible solution for this. What I was thinking of was to create a function to see if the CPT has a post count of 0, then execute a code to exclude the specific page from displaying in the navigation. –  Roc Mar 23 '13 at 6:33
add comment

1 Answer

So I've come up with a solution - although I am not sure if this is the best, as it outputs CSS, something I prefer not to do.

In the header.php of the theme:

<?php $published_posts = wp_count_posts('CPT1')->publish;
    if ( $published_posts == 0 ):
    echo '<style>.page-item-8{display:none;}</style>';
endif ?>

<?php $published_posts = wp_count_posts('CPT2')->publish;
    if ( $published_posts == 0 ):
    echo '<style>.page-item-9{display:none;}</style>';
endif ?>

This is for 2 separate CPTs. As you can see, it checks if the CPT has a post. If not - the CSS will display in the .

However, I am wondering if there may be a way to accomplish this same thing through the functions.php of the theme file?

Thanks!

share|improve this answer
add comment

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.