Solved

is_page

Posted on 2011-03-10
10
322 Views
Last Modified: 2012-05-11
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?
0
Comment
Question by:petewinter
10 Comments
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 35093271
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
 
LVL 8

Expert Comment

by:pdd1lan
ID: 35093285
0
 

Author Comment

by:petewinter
ID: 35093300
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
 

Author Comment

by:petewinter
ID: 35093313
pdd1lan - Thanksm but still no good?

<?php if (is_page('2'));  { ?>
 
       
        hello
       
        <?php } ?>
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 92

Accepted Solution

by:
objects earned 250 total points
ID: 35093327
>  <?php if (is_page('2'));  { ?>

get rid of that semi-colon


<?php if (is_page('2'))  { ?>
0
 
LVL 34

Assisted Solution

by:Beverley Portlock
Beverley Portlock earned 250 total points
ID: 35093355
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
 

Author Comment

by:petewinter
ID: 35093367
bportlock - Sorry should have gave you points too.
0
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 35093415
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
 

Author Closing Comment

by:petewinter
ID: 35116633
Many thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article discusses four methods for overlaying images in a container on a web page
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now