Support » Themes and Templates » is_page to display/not display some code

  • Hello, does anyone know how I could get WordPress to not display some code on Pages, whilst displaying it on Posts? Specifically, I want the “Posted by *author* on *date* in *category*” bit to not appear on pages.

    All I know for sure is that I’ll be using is_page to determine that a Page is loaded. Here’s the bit I want to be hidden on Pages:

    <?php _e(“Posted on “); ?> <?php the_time(‘F jS, Y’) ?> in <?php the_category(‘,’) ?> by <?php the_author() ?> <?php edit_post_link(‘Edit’, ‘ | ‘, ”); ?>

    I read the Codex page on Conditional Tags ( but after fiddling with the syntax examples given there, I just can’t seem to get it to work.

    Can anyone help?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hi Sugarrocket,
    You could do something similar to:

    <?php if(!is_page()) : show code; endif; ?>

    (Of course, replace ‘show code’ with the code you want displayed.)

    Another way to *not* display the post meta info when someone’s viewing a page is to create a page template (page.php file) and simply remove the post meta code from it. That template will be used each time a user visits a page and single.php (or index.php) will be used while viewing a single post.

    Hope that helps.

    I hadn’t thought about adding another template. That’s a good work around, but I tend to tweak my template frequently so making changes on both will probably lead to different looking pages at some point!

    I figured the code would be simple enough, but it’s the syntax that’s tripping me up. I generally understand the idea of most WP code, but the devil’s in the details. (Did I use enough brackets? When do I single quote? Wait, 2 equal signs?) I know I can’t just chuck the code in place of “show code”, but I’m unsure how to go about it. I’ve looked at a lot of example code, but copying that syntax hasn’t worked either : \

    Any super-coders out there who can help me out?

    For this Pages issue you shouldn’t struggle with the conditionals. The normal way to address it (and not a “workaround”!) is to have a page.php template – as it was suggested above.

    I see more upsides to the “workaround” than the “normal fix”, and still hope to use the conditionals. If anyone knows how to do this please contact me and I’ll pay you for your time. Thanks.

    No need for money (well…). The basics were in wpdiva’s reply:

    <?php if(!is_page()) : ?>
    <?php _e("Posted on "); ?> <?php the_time('F jS, Y') ?> in <?php the_category(',') ?> by <?php the_author() ?> <?php edit_post_link('Edit', ' | ', ''); ?>
    <?php endif; ?>

    if(!is_page()) means “if this is NOT a Page” (! = not).

    This worked beautifully, THANK YOU! I figured it would be terribly simple, but my tries were more complicated. Dur.

    Kafkaesqui, thank you. That’s just what I needed to get the “Uncategorized” category off my Pages!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘is_page to display/not display some code’ is closed to new replies.