• Hi I have site where I need to include a template if a page is a descendent of a grandfather page.

    At the moment I have a conditional statement that searches for child pages of subcategory but I really need to have a conditional that looks for the main category instead. If I cannot get this to work the client will need me to update menu manually each time a new subcategory is created which is less than ideal.

    Here is what I am using at the moment:

    if ($post->post_parent == '69'|| $post->post_parent == '82'|| $post->post_parent == '15'|| $post->post_parent == '15') {
      include (TEMPLATEPATH . '/collection-seating-accordian.php'); 
    
    }

    The id of the main category/grandfather page is 71.

    Thanks!

Viewing 1 replies (of 1 total)
  • it is totally not clear where you are applying your conditional statement, because your are mixing pages and categories:
    the following is for the category archive:

    this will build an array with all the ancestor category ids of the current category archive; and check for the grandparent ancestor of the category:

    $cat_id = get_query_var('cat'); // get the category id for the test
    	$cat_ancestors = array();
             $grandparent_cat = '';
    	$cat_ancestors[] = $cat_id;
    	do {
    	$cat_id = get_category($cat_id);
    	$cat_id = $cat_id->parent;
    	$cat_ancestors[] = $cat_id; }
    	while ($cat_id);
    	if($cat_ancestors[2]) $grandparent_cat = $cat_ancestors[2];
Viewing 1 replies (of 1 total)

The topic ‘Conditional for a Grandfather Page’ is closed to new replies.