0

I have a website with 5 main pages (consider them as sections), then 3-5 sub pages for each of them. I would like to display a flash banner for each section, i.e. it should display the flash banner on that page and all its sub pages.

Right now i am able to get that o the main page by using the following code.

<?php if (is_page('our-school-district')) { ?>
                    <object width="664" height="217">
                        <param name="movie" value="<?php bloginfo('url'); ?>/wp-content/uploads/2011/03/school_district.swf" />
                        <param name="wmode" value="transparent" />
                        <embed src="<?php bloginfo('url'); ?>/wp-content/uploads/2011/03/school_district.swf" width="664" height="217" wmode="transparent"></embed>
                        <!-- It Is Not Just About The Seeds That Are Planted, but the Garden That Surrounds Them. -->
                    </object>                    
                    <?php } ?>

How do I get it on all sub pages too?

2 Answers 2

1

You can do that by using this nice little function:

function is_page_or_child_of($slug){
    global $post;
    if (empty($slug))
        return false;
    //is it the page?
    if ($post->post_name = $slug) 
        return true;
    //check the children
    $page = get_page_by_path($slug);
    $children = get_pages('child_of='.$page->ID.'&sort_column=post_date&sort_order=desc');
    foreach ($children as $sub){
        if ($post->ID == $sub->ID){
            return true;
        }
    }
    return false;
}

and instead of using is_page('our-school-district') use s_page_or_child_of('our-school-district')

0

You should create a template for each page that way you can add the banner directly to it without having to mess with a bunch of php unless the banner will be outside of the page template view this link for a better explanation Wordpress Codex - Pages

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.