Jump to content

Conditional Statement in PHP


Guest excelweb

Recommended Posts

Guest excelweb

Hi, I'm using a pagelines WP template. I have designed and put together a page within the template however I am trying to put a conditional statement in that will allow me to add different text to footer for one page than the rest of the site (the template has a generic footer that is the same for every page on the site otherwise). What code do I use and where do I enter this? Thanks in advance!

Link to comment
Share on other sites

Wordpress makes this pretty simple: http://codex.wordpress.org/Conditional_Tags#A_PAGE_Page

 

Assuming you are dealing with a "page" (rather than a "post" or custom post type), you would need to edit the page.php file located within yourwebsite.com/wp-content/themes/yourthemename/.

 

Look for the line near the bottom of the page:

 

<?php get_footer(); ?>

 

You can then replace it with a bit of PHP which looks at the page id:

 

<?php 
  if (is_page(100)) 
  {
?>
...Put the HTML content that you want to appear within this page here...
<? 
  } 
  else 
  {
     get_footer(); 
  }
?>

 

You would need to change the "100" with the id of the page you want custom content to appear on. You can find that id by logging into the Wordpress admin, going to the Pages section, and editing the page that you want to add the custom text to. You should see something like this:

 

http://yoursite.com/wp-admin/post.php?post=2&action=edit

 

The "2" in the above, between the "post=" and the "&" within the URL is the id of the page.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...