Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

is_page

Posted on 2011-03-10
10
Medium Priority
?
343 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
9 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

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

<?php if (is_page('2'));  { ?>
 
       
        hello
       
        <?php } ?>
0
 
LVL 92

Accepted Solution

by:
objects earned 1000 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 1000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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 update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…
Suggested Courses

879 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