Solved

is_page

Posted on 2011-03-10
10
325 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to create an extensible mechanism for linked drop downs.
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
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…

823 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