conditional for sub category on archive page

You are looking for the cat_is_ancestor_of() function. https://codex.wordpress.org/Function_Reference/cat_is_ancestor_of The example in the WP codex is very close to what you are attempting for your archive template. <?php // if the category is music or a music SUBcategory, if (cat_is_ancestor_of( 4, $cat ) or is_category( 4 ) ): ?> <div id=”music_subnav_menu” class=”subnav_menu”> <?php wp_nav_menu( array( ‘menu’ … Read more

Display the featured image from the last post

This should work. I’ve modified your $args a little and surrounded your echoed code within the while(have_posts()) : the_post(); loop, then added the the_post_thumbnail() function and, finally, the wp_query_reset(); at the bottom: <?php $limit = 999; $counter = 0; $categories = get_categories(); foreach ( $categories as $category ): if ( $counter < $limit ) { … Read more

Custom sidebar on category pages

one way to accomplish your goal would be to create a child theme (https://codex.wordpress.org/Child_Themes). You create a folder inside /wp-content/themes/, then add a style.css file inside it with a few comment lines at the top to tell WordPress this is a child theme of whatever your current theme is. Sample style.css file: all you need … Read more

How do I get a list of all categories that a given user has written blog posts for?

As, much as I know about WordPress we have to ways to achieve this. First: You have to retrieve all posts written by an author an then you can fetch categories assigned to those posts. Store them in an array uniquely. $args = array(‘author’ => $author->ID, ‘posts_per_page’ => -1, ‘fields’ => ‘ids’); $authorArticles = get_posts($args); … Read more

Get all sub-categories of a parent category

In reply to your updated code, you should know that the $post_terms = wp_get_object_terms() would only return categories that directly attached to the post, so I’d just use wp_list_categories() to get and display the child categories for the given (or a known) parent category. And here’s the code that works well for me which displays … Read more

get_cat_ID() not wokring

get_cat_ID gets the ID of a category based on the name. “Category” is a specific taxonomy named category. You’re trying to get the ID of a Product Category (product_cat). You cannot use get_cat_ID() to get the ID of a custom taxonomy. To do that you need to use get_term_by(): $product_cat = get_term_by( ‘name’, $cat_name, ‘product_cat’ … Read more

What’s the Simplest Way to Override/Rewrite the %category% Permalink Structure Tag?

Yes, the post_link_category hook is indeed what you would use to filter the %category% replacement value in the permalink. And here’s an example with prominent_cat being the meta key and the value being the category name (e.g. Pizza Hut), where I’m using get_term_by() to get the category object/data: add_filter( ‘post_link_category’, ‘my_post_link_category’, 10, 3 ); function … Read more