Extract image url associated to a category

I found what I needed: $category = get_category( get_query_var( ‘cat’ ) ); $cat_id = $category->cat_ID; $images = get_posts( array(‘post_type’ => ‘attachment’, ‘category__in’ => $cat_id)); if ( !empty($images) ) { foreach ( $images as $image ) { $image_url = $image->guid; } } else{ $image_url=””; } First I got the category, and current category ID I’m in. … Read more

How to Customize the category list page

WordPress determines which template file to use from its Template Hierarchy. It might be further customized by extensions and themes might be using different files for same things, depending on what they do. There are helper plugins for simpler cases (for example What The File), but it might require involved debug with more complex themes.

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