Get current_parent_category in a loop or Cat ancestor- big problem

You could use get_ancestors(). You can transform this: <a href=”#” class=”<?php $category = get_category($cat); echo $category->category_nicename;?>”><?php single_cat_title(”) ?></a> Into this (I don’t know what $cat is as you have not shown it in your question, I assume it is a category ID, if not, you have to provide category ID): <?php $cat_ancestors = get_ancestors( $cat, … Read more

Post count for category and tag

Don’t run a custom query to get the post count. This is already done by the main query. What you are doing is the same as eating the same piece of meat twice. 🙂 As said, the main query already return the amount of posts found via the $found_posts property. You can access and display … Read more

How to display only posts assigned to a particular, isolated, subcategory

We can change the default behaviour of including posts attached to child categories by mapping the category_name query var (set from pretty permalinks) to category__in (which ignores child categories): function wpse_184127_ignore_category_children( $wp_query ) { if ( $wp_query->is_main_query() && $wp_query->is_category() && $name = $wp_query->get( ‘category_name’ ) ) { if ( $term = get_term_by( ‘slug’, sanitize_title_for_query( $name … Read more

create a page which displays a list of categories title+ short description?

You just need to add some conditional to aplly the filter or not. For example, if you don’t want to apply the trimming on category archive pages, one possible solution could be: add_filter( ‘category_description’, ‘cyb_trim_category_desc’, 10, 2 ); function cyb_trim_category_desc( $desc, $cat_id ) { // Apply only if we are not in category archive template … Read more

wp_list_categories depth and number

You should add ‘child_of’ => 0, That way you will display only Main categories aka children of 0. $custom_args = array( ‘orderby’ => ‘name’, ‘order’ => ‘ASC’, ‘child_of’ => 0, ‘depth’ => 1, ‘number’ => 4, ); wp_list_categories($custom_args); If you want to get WooCommerce categories try this: function getCustomProductCats () { $orderby = ‘name’; $order=”asc”; … Read more

shop page with all categories with paginate

i think it is petty straightforward solution first get your all categories list by help of get_categories() function and loop though and find the post relative with that. <?php $categories = get_categories(); return all categories foreach( $categories as $cat ){ $query = new WP_query([‘cat’=>$cat->term_id, ‘postes_per_page’=> 10]); if( $query->have_postes() ){ echo $cate-name; // this this category … Read more