[resolved] Use different page layout if child category? (3 posts)

  1. sparklogix
    Posted 2 years ago #

    I am modifying the category.php file to have 3 different layouts. One will be the standard layout for our theme, the other will be full-width, removing the sidebar if it is in the Articles category. I also need to the non-sidebar layout to be used on any child category of the Articles category. I can't specify certain cat names or IDs in the category.php file because they won't always be the same.

    Right now, my category.php file looks like this:

    <?php if (is_category( 'Articles' )): ?>
      /*non-sidebar content goes here*/
    <?php else: ?>
      /*regular category content goes here*/
    <?php get_sidebar(); ?>
    <?php endif; ?>
    <?php get_footer(); ?>

    I've done a search looking for how to do this, but haven't been able to find anything. Thanks for the help!

  2. Michael
    Forum Moderator
    Posted 2 years ago #

  3. sparklogix
    Posted 2 years ago #

    Perfect! Thanks! I had tried using the cat_is_ancestor_of but couldn't get it working because I didn't want to use the cat ID. Didn't think to combine them.

    Used this code and it worked perfectly:

         $category_id = get_cat_ID('Articles');
         $q = 'cat=' . $category_id;
     if (cat_is_ancestor_of($category_id, $cat) or is_category($category_id)):  ?>

    Thanks again!

Topic Closed

This topic has been closed to new replies.

About this Topic