How to customize category template?

Here is your solution- <?php /** * The template for displaying category archive pages. * * @link https://codex.wordpress.org/Template_Hierarchy * * @package Codilight_Lite */ $cat = get_category( get_query_var( ‘cat’ ) ); $cat_id = $cat->cat_ID; $child_categories=get_categories( array( ‘parent’ => $cat_id, // Uncomment the below line if you want empty category to appear on the list. // ‘hide_empty’ … Read more

How to list child categories?

After some trial and error I managed to come up with the following: <?php if (is_category( )) { $cat = get_query_var(‘cat’); $thiscat = get_category ($cat); $parent = $thiscat->parent; if ($parent != ”) { wp_list_categories( array( ‘child_of’ => $parent, ‘exclude’ => $cat ) ); } else { wp_list_categories( array( ‘child_of’ => $cat ) ); } } … Read more

Show all posts for a specific category/author

The number of posts displayed in any loop by default is controlled by Settings > Blog pages show at most. To show all posts, you can enter a huge number, but -1 (which is the value to use for the posts_per_page paramerter in WP_Query) does not work here. It is possible to show all posts … Read more

Limit number of terms that a custom taxonomy can save per custom post type

Taxonomy Single Term is a small library that helps to implemement this functionality. Usage Include the class.taxonomy-single-term.php file from within your plugin or theme Initialize the class (update the taxonomy slug with your own): $custom_tax_mb = new Taxonomy_Single_Term( ‘custom-tax-slug’ ); Optional The second parameter is an array of post_types and the third parameter is either … Read more

Random post + categories + tags

You had it right with categories, just do the same for tags (using get_term_link instead) – better yet, use the core WordPress functions that automatically generate a list of category/tag links: function random_post_shortcode( $atts ) { $posts = get_posts( array( ‘numberposts’ => 1, ‘category_name’ => ! empty( $atts[‘category_name’] ) ? $atts[‘category_name’] : null, ‘orderby’ => … Read more

Display children of the category a post is assigned to

get the category or categories of the single post with get_the_category() and loop through them, calling the child category lists if available. <ul> <?php if( is_single() ) { $post_cats = get_the_category(); foreach( $post_cats as $post_cat ) { wp_list_categories( array( ‘child_of’ => $post_cat->term_id, ‘title_li’ => 0, ‘show_option_none’ => ” ) ); } } ?> </ul>