How can I display the number of post associated to a category in Twig/Timber WordPress? [closed]

You’re assuming that get_terms() returns an object with a count property, but it doesn’t. From the docs: Return (WP_Term[]|int[]|string[]|string|WP_Error) Array of terms, a count thereof as a numeric string, or WP_Error if any of the taxonomies do not exist. See the function description for more information. Also, the way you’re calling get_terms() is deprecated. There … Read more

How to display sticky or latest published post on the current category page it belongs to?

This code is certainly not perfect but it actually does the job : <?php // Store the current category ID : $current_object = get_queried_object_id(); // Get sticky post : $args = array( ‘posts_per_page’ => 1, ‘post__in’ => get_option( ‘sticky_posts’ ), ‘cat’ => $current_object, ‘ignore_sticky_posts’ => true, ); $sticky_query = new WP_query( $args ); // Get … Read more

How do I add a tag slug to a category URL to filter posts?

Ok, I found a solution. By default in WP there is an option to filter categories by tags. E.g. https://example.com/category_name?tag=tag_name. I added a rewrite rule and redirection: https://developer.wordpress.org/reference/functions/add_rewrite_rule/ add_action( ‘init’, function () { add_rewrite_rule( ‘([a-z0-9-]+)\/tag\/([a-z0-9-]+)\/?$’, ‘index.php?category_name=$matches[1]&tag=$matches[2]’, ‘top’ ); } ); https://developer.wordpress.org/reference/hooks/template_redirect/ add_action( ‘template_redirect’, function () { if ( is_category() && is_tag() && ! empty( $_GET[‘tag’] … Read more

Having problems with paging

Correct me if I’m wrong. I guess you use that code to custom display a category. If that’s the case, right before this code: <?php while (have_posts()) : the_post(); ?> You will need to add query_posts(): <?php query_posts(‘cat={categoryID}&paged=’ . $page); ?>

List Child Categorie and hide the parent

You need to add &title_li= to your code like so to remove the word “Categories”: <?php wp_list_categories(‘orderby=id&show_count=0&use_desc_for_title=0&child_of=5&title_li=’); ?> More information on categories can be found in the codex here: http://codex.wordpress.org/Template_Tags/wp_list_categories

Categories will only display links to posts

Look in your theme’s folder for a file called “category.php”. Open it then look for something like this: <span><a href=”https://wordpress.stackexchange.com/questions/7088/<?php the_permalink();?>”><?php the_title();?></a></span> Place this right below it: <p><?php the_excerpt();?></p> That will display an excerpt of each post below the title.