Solved

is_page

Posted on 2011-03-10
10
318 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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 …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult 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…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

708 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

11 Experts available now in Live!

Get 1:1 Help Now