Theme for subcategories

You could use the template_redirect hook to check and see if your post is a category and then whether it is a sub-category … and if so, force a different template. For example (assuming you are using wordpress categories) function my_maybe_override_category_template( $template ) { # Make sure you are about to show a category term … Read more

Why is my sub-category template showing the wrong posts

Remove query_posts and add a pre_get_posts action to your functions.php file to modify sort order: function wpd_category_sort_order( $query ) { if ( !is_admin() && $query->is_category() && $query->is_main_query() ) { $query->set( ‘order’, ‘ASC’ ); } } add_action( ‘pre_get_posts’, ‘wpd_category_sort_order’ );

Getting the first parent of a hierarchical term

Since you are in a Single Post you’ll need to first get the categories then use get_ancestors() to display the hierarchy. $product_cats = wp_get_post_terms( get_the_ID(), ‘product_cat’ ); if( ! empty( $product_cats ) ) { $single_cat = array_shift( $product_cats ); $product_ancs = get_ancestors( $single_cat->term_id, ‘product_cat’ ); if( ! empty( $product_ancs ) ) { $top_level_cat = array_shift( … Read more

Adding a page summary to a specific page

You can use wp_list_pages with the child_of argument: /** * Display hierarchical list of all posts for a given post. * * @param int|WP_Post $post Display for post. Defaults to current post/page. */ function wpse_184554_list_section( $post = null ) { if ( ! $post = get_post( $post ) ) return; if ( $post->post_parent && $ancestors … Read more

Style a category from category list

You can try looping to match the category name you need. $categories = get_the_category(); $category_name=”foo1″; // set this to the category name you want to show $output=””; if($categories){ foreach($categories as $category) { if ( $category_name == $category->cat_name) { $output .='<div class=”category-custom-class”>’.$category->cat_name.'</div>’; } else { $output .='<div class=”category-custom-class1″>’.$category->cat_name.'</div>’; } } echo $output; }