• I am using a condition like this in the page.php file:

    <?php
    $ancestors = get_post_ancestors($post);
    if (is_page('3'))
    	{
    	include(TEMPLATEPATH . '/content0.php');
            }
    else
    if (is_page('5') || in_array(5,$ancestors))
    	{
    	include(TEMPLATEPATH . '/content1.php');
    	}
    else
    	{
    	include(TEMPLATEPATH . '/content2.php');
    	}
    ?>

    The thing is that I am also having pages finishing like this: https://www.mydomainname.com/?page_id=94&category=8&product_id=16 (I am using the wp-ecommerce plugin).

    Here, page 94 is child of page 5 but the ‘&category=8&product_id=16’ stuff in the address make this code above inefficient.

    Can you help me here?

    ps: WordPress4Ever .)

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter tomasi514

    (@tomasi514)

    Nobody can help me with a solution here?

    nathan12343

    (@nathan12343)

    This is what I use to set stylesheets for different sections of content. I’ve had a go at adapting it for your site (but untested, of course):

    <?php
    function is_tree($p_id) {
    	global $post;
    	if(is_page()&&(in_array($p_id, $post->ancestors) ||
    	$post->post_parent==$p_id ||
    	is_page($p_id)))
    	return true;
    	else return false;
    };
    ?>
    <?php if (is_page('3')) {
    	include(TEMPLATEPATH . '/content0.php');
            }
    if (is_tree(5)) {
    	include(TEMPLATEPATH . '/content1.php');
    	}
    else {
    	include(TEMPLATEPATH . '/content2.php');
    	}

    Please note that I am getting an error of ‘wrong datatype’ if a 404 page appears (which is how I found your post)

    Hope this helps

    nathan12343

    (@nathan12343)

    apljdi solved the error on 404.

    Replace the relevant line above with:

    if(is_page()&&(in_array($p_id, (array)$post->ancestors) ||

    Works like a charm for me!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Special Condition with ancestors’ is closed to new replies.