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 am trying to stop latest blog items from displaying in the blog section of my site. I have used the following code:

    <?php  if ( is_page('blog') ) { ?>
        <h2>Don't display anything</h2>
    <?php } /* for all other pages */ 
    else { ?>
        <h2>Display blog</h2>
    <?php } ?>

However, whenever I am on the blog page it displays "Display Blog", completely ignoring the if statement.

Is there something I'm missing from getting this working?

share|improve this question
    
Did you try is_page(XX) with your blog's page ID instead of slug? –  Geert Jan 20 '12 at 12:59
    
I have tried is_page('14'), is_page(14), the title and the slug. Nothing works. –  mickburkejnr Jan 20 '12 at 13:05
    
Where did you put your PHP code? To debug also try: global $post; var_dump($post);. –  Geert Jan 20 '12 at 13:20
    
I put it in the sidebar.php file of the twentyeleven theme that came with it. Trying to debug now. –  mickburkejnr Jan 20 '12 at 13:22
    
Be aware of these notes too: codex.wordpress.org/Function_Reference/is_page#Notes –  Geert Jan 20 '12 at 13:27
show 2 more comments

2 Answers

up vote 1 down vote accepted

Assuming that the 'blog' slug is correct, your code would work. I would suggest making a separate template for the page, namely page-blog.php (see http://codex.wordpress.org/images/1/18/Template_Hierarchy.png and http://codex.wordpress.org/Template_Hierarchy) where you set up the structure and appearance of the page exactly as you want it to be.

WordPress will automatically look for the file when opening a page with the name of 'blog' (that is, the slug must be 'blog'). Also, the code you posted above would normally go in loop.php, granted that you are using the default template-setup.

share|improve this answer
add comment

It's much easier to use a plugin like WordPress › Widget Logic « WordPress Plugins

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.