PHP "if" statement question

Discussion in 'Web Design and Development' started by ElectricMan5, Oct 3, 2009.

  1. ElectricMan5 macrumors regular

    Joined:
    Jul 22, 2008
    #1
    I wish to exclude the whole "<p class="postmeta"> </p>" section from a certain page. Now, I know how to make it appear on one or more pages, but how do I make it appear on all, but exclude the pages I enter in? I keep
    PHP:
    <?php if (is_page()) { ?> 
    <?php ?>
    in it, because the empty () puts it on every page...

    I was trying to use
    PHP:
    <?php if (is_page(23)) { ?>
    //blank space is here, so nothing shows up
    <?php ?> 
    inside of it, since I don't want it appearing on page 23, but it didn't work.


    Here's the code I'm trying to work with:


    PHP:
    <?php if (is_page()) { ?>   


                        <p class="postmeta">    
        

                            <a href="<?php comments_link(); ?>" class="comments">Comments (<?php comments_number('0','1','%'); ?>)</a> |        

                            <span class="date"><?php the_time('F jS, Y'); ?></span><?php edit_post_link('Edit'' | '''); ?>

                        </p>

    <?php ?>

    Thanks!
     
  2. ElectricMan5 thread starter macrumors regular

    Joined:
    Jul 22, 2008
    #3
    I got it :)

    Just made the top statement
    PHP:
    <?php if (is_page('23')) { } else {  ?>
    PHP:
    <?php if (is_page('23')) { } else {  ?>

                        <p class="postmeta">    
        

                            <a href="<?php comments_link(); ?>" class="comments">Comments (<?php comments_number('0','1','%'); ?>)</a> |        

                            <span class="date"><?php the_time('F jS, Y'); ?></span><?php edit_post_link('Edit'' | '''); ?>

                        </p>

    <?php ?>
     
  3. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    If you want something more succinct the ! lets you invert the condition.
    PHP:
    <?php if (!is_page('23')) {  ?>
     
  4. ElectricMan5 thread starter macrumors regular

    Joined:
    Jul 22, 2008
    #5
    Cool, so the ! pretty much makes it mean "exclude page 23 from..."?
     
  5. neoserver macrumors 6502

    Joined:
    Apr 24, 2003
    #6
    Essentially yes. The ! operator inverts the logic. (i.e making the if test for FALSE instead of true.) In your case it turns the if statement into this:

    IF page IS NOT 23 then...

    instead of IF PAGE is 23 THEN do nothing, ELSE do something.
     
  6. ElectricMan5 thread starter macrumors regular

    Joined:
    Jul 22, 2008
    #7
    Yeah I guess that's a lot simpler. Thanks a lot!
     

Share This Page