Category Template to Show Different Elements for Child Categories
-
I’m looking at this idea for my category (archive.php) template:
– if it is a child category page
Show post titles only– if it is a parent category page
Show the regular title photo, excerpt, etc.<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <!-- parent/child template --> <?php $cat_obj = $wp_query->get_queried_object(); if( $cat_obj->parent ) : ?> <!-- child category --> <h4><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a> <?php edit_post_link(__('<span class="edit_link">Edit</span>')); ?></h4> <?php else : ?> <!-- parent category --> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a> <?php edit_post_link(__('<span class="edit_link">Edit</span>')); ?></h2>
etc.
It totally works fine. But I want to show 10 posts for the child category instead of the default. The default would still show for the parent.
This seemed like an easy task until I started trying to figure it out. Can anyone help, please? I’d be happy to trade for any design/css tip you may need.
- The topic ‘Category Template to Show Different Elements for Child Categories’ is closed to new replies.