using is_page() conditional tags in themes

How and where to use is_page() conditional tag :

1)  Login to Administrator section

2) Pages > Add New

3) Give title as “About” and publish it.

If page.php is not there in wp-content/themes/current_theme folder, than wordPress will use index.php of the current theme to display the content.

If page.php is there and we want that “About” page should have some different look than other pages, then use the following  to achieve it:

1) Create a template file named “About.php” file same as page.php file in wp-content/themes/current_theme folder

2) Do formatting as per your needs.

3) Edit the page.php file as mentioned below :

get_header(); ?>

// use is_page conditional tag to check whether template file exists for “About” page

<?php if (is_page(‘About’)) { ?>

<?php include(“About.php”); ?>   // if template file exists than include the “About.php” file
<?php } else { ?>

// Other pages will use this section for displaying the content
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(‘<p>Read the rest of this page &raquo;</p>’); ?>
<?php wp_link_pages(array(‘before’ => ‘<p><strong>Pages:</strong> ‘, ‘after’ => ‘</p>’, ‘next_or_number’ => ‘number’)); ?>
<?php } ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

IMP:

The template file name and the name used in is_page() must be same as page title mentioned in creating page in administrator section.

for e.g : if page title is “About” then

1) create template file with name About.php

2) use page title in is_page() as is_page(‘About’)

Advertisements

2 Comments »

  1. 1
    kalinga Says:

    Hey Dear

    Nice posts this really really help full for me

    Thnx u Very much

  2. 2
    Jeanne Says:

    Howdy would you mind letting me know which webb host you’re using?
    I’ve lowded your bloog in 3 different interne browsers and I must say tthis blog loads a lot faster then most.

    Can you recommend a good hosting provider at a honest price?
    Thanks, I appreciate it!


RSS Feed for this entry

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: