tomasi514
Member
Posted 2 years ago #
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: http://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 .)
tomasi514
Member
Posted 2 years ago #
Nobody can help me with a solution here?
nathan12343
Member
Posted 2 years ago #
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
Member
Posted 2 years ago #
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!