WordPress.org

Ready to get started?Download WordPress

Forums

is_page to display/not display some code (9 posts)

  1. sugarrocket
    Member
    Posted 7 years ago #

    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 (http://codex.wordpress.org/Conditional_Tags) but after fiddling with the syntax examples given there, I just can't seem to get it to work.

    Can anyone help?

  2. wpdiva
    Member
    Posted 7 years ago #

    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.

  3. sugarrocket
    Member
    Posted 7 years ago #

    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 : \

  4. sugarrocket
    Member
    Posted 7 years ago #

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

  5. moshu
    Member
    Posted 7 years ago #

    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.
    See http://codex.wordpress.org/Template_Hierarchy

  6. sugarrocket
    Member
    Posted 7 years ago #

    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.

  7. Kafkaesqui

    Posted 7 years ago #

    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).

  8. sugarrocket
    Member
    Posted 7 years ago #

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

  9. workerbeej
    Member
    Posted 7 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic