if is_page question in WordPress

1 replies
Hi Guys,

Quick question. I'm trying to show content on different pages dynamically using the if is_page option in WordPress.

i.e. if is page = contact, then I want to have a dynamic portion of the page i.e. I will code it from the page template in the theme editor to show different text, video pictures etc than if is_page = about.

So far I'm using the code

PHP Code:
    <?php if ( is_page('My Page') ) { ?>

    Don't know what to put here!!!!

    <?php ?>\
Do I have to have some sort of "then" command, i.e. if ( is_page('My Page') )

Then show (this text)

I know this is really basic stuff but I'm having trouble finding the answer and what better place than the good ol' warrior forum to get the answer.

Thanks in advance guys and gals
#ispage #question #wordpress
  • Profile picture of the author kalel1
    PHP Code:

    <?php if ( is_page(&#8216;My Page’) ) { ?>

        <!-- code here will be show to "my page"-->
        <?php the_excerpt(); ?>


    <?php } else { ?> 

        <!-- code here will be show to all other pages -->
        <?php the_conetnt(); ?>

    <?php ?>


    This code assumes that you want a certain page to show only the excerpt of the content, instead of the content itself, and show the regular content on the rest of the pages.

    Please note it won't actually work this way, you have to have the wordpress loop* in there instead of just <?php the_excerpt(); ?> but the point is that in those areas you put whatever code you'd like (html or wordpress template tags**).

    An actual example could be this, which give you a slightly different template for your page as opposed to the rest (h2 instead of h1 for the title)


    PHP Code:
    <?php if ( is_page(&#8216;My Page’) ) { ?>

        <?php if (have_posts()) : ?>
                   <?php while (have_posts()) : the_post(); ?>    
                   <h1><?php the_title(); ?></h1>
                   <?php the_content(); ?>
                   <?php endwhile; ?>
         <?php endif; ?>

    <?php } else { ?> 

        <h1><?php the_title(); ?></h1>
                   <?php if (have_posts()) : ?>
                   <?php while (have_posts()) : the_post(); ?>    
                   <h2><?php the_title(); ?></h2>
                   <?php the_content(); ?>
                   <?php endwhile; ?>
         <?php endif; ?>

    <?php ?>
    * found here: codex.wordpress.org/The_Loop]
    ** found here: codex.wordpress.org/Template_Tags
    {{ DiscussionBoard.errors[4103793].message }}

Trending Topics