Support » Fixing WordPress » Show a div only in certain pages AND their sub-pages

  • Ok, how can i do that?

    I have 4 main product pages, each one of ’em has some sub-pages.
    I want to show different content in the header for each of one of these for group of pages.

    Any idea?

    Thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • I would use some WordPress conditional tags. You can check if you are on a certain page or on a sub page.

    Actually i was looking for a definition for sub-pages, because i keep adding them and i don’t want to constantly (and manuallly) update my code with new ID.

    Check against $post->post_parent if you are inside a Loop.

    I’ve found this code, which works fine for me, in theory. Actually, i can’t make it work on subpages. Maybe bacause i dind’t change the number beside the page name (‘2′, ’56’, ’15’)? What are they?

    <?php
    if ( is_page( 'about' ) || '2' == $post->post_parent ) {
        // the page is "About", or the parent of the page is "About"
        $bannerimg = 'about.jpg';
    } elseif ( is_page( 'learning' ) || '56' == $post->post_parent ) {
        $bannerimg = 'teaching.jpg';
    } elseif ( is_page( 'admissions' ) || '15' == $post->post_parent ) {
        $bannerimg = 'admissions.jpg';
    } else {
        $bannerimg = 'home.jpg'; // just in case we are at an unclassified page, perhaps the home page
    }
    ?>

    The numbers are the ID’s of the pages. $post->post_parent returns the ID of the parent post. So you’ll want to change those numbers to match the ID’s of the correct pages/posts.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Show a div only in certain pages AND their sub-pages’ is closed to new replies.