How to modify default category widget list display?

If you want to change the appearance, try editing the css that targets the categories. If you want to change the text “Filled under:” (before) or the “,” (sep) that separate the categories, in my Genesis theme I use the following code . Try adapting it by changing genesis_post_meta to your version. add_filter( ‘genesis_post_meta’, ‘sp_post_meta’ … Read more

Display random categories

Sadly get_categories() and get_terms() won’t likely ever support ‘orderby’ => ‘rand’ which really leaves you with two options – get every category and select 5 randomly, or construct your own WP_Query to query categories with ‘orderby’ => ‘rand’. The former is easier to implement, and will likely have better performance (unless you have an very … Read more

Fix Warnings that shouldn’t be necessary to fix

So there’s two things going on here. Firstly get_the_category() doesn’t accept a category ID as a parameter. It accepts a post ID for which to get categories from. Judging by your code you need to use get_category(): $category = get_category( get_query_var(‘cat’) ); The other problem is that you seem to be using $cat_name without checking … Read more

Get and show all of the available categories

It should be noted that both <?php echo get_the_category_list(); ?> and <?php foreach((get_the_category()) as $category){ echo $category->name.”<br>”; echo category_description($category); } ?> display ALL categories that are assigned to the current post in the loop. From your question’s title, I understand that you want to display all available categories that exist in the website, so wp_list_categories() … Read more

How to display parents category and child category separately for a specific post?

This should find an immediate parent for you. // get the current category ID $category_id = get_the_category(get_the_ID()); // get the current category object $child = get_category($category_id[0]->term_id); // get it’s parent object $parent = get_category($child->parent); var_dump($parent->name . ‘ – ‘ . $child->name); The same but in a WordPress loop: $args = [ ‘post_type’ => ‘post’ ]; … Read more