is_page

I am new to wordpress, but can't understand why my below command is not working:

I am just trying to say if the page id is 2 show area.

<?php if (is_page( 2 ));  { ?>
       
        hello
       
        <?php } ?>

However the word "Hello" is showing on every page???

Link: http://www.petewinter.com/wordpress/?page_id=2

Why is this?
petewinterAsked:
Who is Participating?
 
objectsConnect With a Mentor Commented:
>  <?php if (is_page('2'));  { ?>

get rid of that semi-colon


<?php if (is_page('2'))  { ?>
0
 
Beverley PortlockCommented:
It shows up on every page because is_page(2) is always true.

I suspect what you really meant was

<?php  if ( $_GET['page_id'] == 2 )   ?>

and notice there is no ; after the last )
0
 
pdd1lanCommented:
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
petewinterAuthor Commented:
Thanks for the reply. I have changed to the below, but it's still not working:

<?php if ( $_GET['page_id'] == 2 );  { ?>
 
       
        hello
       
        <?php } ?>

Any idea's?
0
 
petewinterAuthor Commented:
pdd1lan - Thanksm but still no good?

<?php if (is_page('2'));  { ?>
 
       
        hello
       
        <?php } ?>
0
 
Beverley PortlockConnect With a Mentor Commented:
The semi colon I told you not to put in is back

if ( $_GET['page_id'] == 2 );

use this instead

if ( $_GET['page_id'] == 2 )

That ; is your THEN clause. The semi colon gives you an IF with an empty THEN
0
 
petewinterAuthor Commented:
bportlock - Sorry should have gave you points too.
0
 
Beverley PortlockCommented:
Well - you can always "request attention" if you want to reallocate the points. There is a link for that up in the original question (bottom right corner).

Regards

BP
0
 
petewinterAuthor Commented:
Many thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.