Forums

[resolved] php q: Is this page a descendant of this category (2 posts)

  1. alextababa2
    Member
    Posted 1 year ago #

    Hi. I'm trying to setup an if condition to display two different index templates.

    If the page is not category 'art' or it's descendants, display the normal loop page.

    If it is, display the 'art' loop page.

    Trouble is I'm not skilled enough to hack together php for discovering if a category is child of a category.

    Here's what I've got, which works, except for detecting if the category is a child of 'art'

    <?php $id = get_cat_id('art'); ?>
    <?php if ( is_category('$id') || is_category ( $parent = $id ))    
    
    	 echo include(TEMPLATEPATH . '/loop-art.php');
             else echo include(TEMPLATEPATH . '/loop-normal.php'); 
    
      ?>

    I've done quite a bit of looking around - I always do before I ask for help... so suggestions will be very appreciated.

    Ali

  2. alextababa2
    Member
    Posted 1 year ago #

    I solved this myself... oooh yeah... using this thread http://wordpress.org/support/topic/380233?replies=3

    I'm still a total hack though.

    <?php $cat_id = get_query_var('cat'); ?>
    <?php $id = get_cat_id('art'); ?>
    <?php if ( is_category($id) || cat_is_ancestor_of( $id , $cat_id ))

    echo include(TEMPLATEPATH . '/loop-art.php');
    else echo include(TEMPLATEPATH . '/loop-normal.php');

    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic