How can I create a Category Index page that lists all categories?

1 – Create a custom template file in your theme e.g “my-custom-template.php” 2 – Create a page from the dashboard, and in the page attributes box(Right sidebar), select the custom template you’ve juste created as a Model. 3 – use wp_list_categories to get the list of your available categories… hope this helps you out.

Get all subcategories and related posts

Try using these codes: if( isset( $sub_category ) ){ echo ‘<b>more items in: </b>’ . $sub_category->name; $args = array( ‘cat’ => $sub_category->term_id, ‘post__not_in’ => array( get_the_ID() ) ); $relatedpostsinsubcategory = new WP_Query( $args ); if( $relatedpostsinsubcategory->have_posts() ){ while( $relatedpostsinsubcategory->have_posts() ){ $relatedpostsinsubcategory->the_post(); ?> <a href=”https://wordpress.stackexchange.com/questions/324478/<?php the_permalink(); ?>” title=”<?php the_title_attribute(); ?>”><?php the_title(); ?></a> <?php } wp_reset_postdata(); } … Read more

How to loop only categories without posts (+ show category featured image with acf) [closed]

Well, in WP the word “loop” is mainly related to posts. It’s easier to say that you want to display categories. All you have to do is to get them using get_categories function and display them. <?php $categories = get_categories( array( ‘orderby’ => ‘name’, ‘order’ => ‘ASC’ ) ); if ( ! empty( $categories ) … Read more

.htaccess too many redirects based on category slug

It’s not clear from what you have posted why you are getting a redirect loop. We would need to see the rest of .htaccess file. However …. You may be getting a conflict with existing mod_rewrite (ie. RewriteRule) directives. Redirect is a mod_alias directive. You no doubt have existing mod_rewrite directives with the WordPress front-controller. … Read more

Warning: sizeof (): Parameter must be an array or an object that implements Countable, On products pages

Let’s take a look at get_the_terms Codex page. We can find there that this function may return: (array|false|WP_Error) Array of WP_Term objects on success, false if there are no terms or the post does not exist, WP_Error on failure. So your code will work correct only in one case – when the function returns an … Read more

List subcategories of a specific product category (adapting from posts to products taxonomy)

…to show the subcategories of a specific category (ID 89) … Try this $product_cats = wp_get_post_terms( $post->ID, ‘product_cat’ ); if ( ! empty( $product_cats ) && ! is_wp_error( $product_cats ) ) { ?> <ul> <?php foreach ($product_cats as $childcat) : ?> <?php if ($childcat->parent == 89)) { ?> <li> <a href=”https://wordpress.stackexchange.com/questions/331894/<?php echo get_term_link($childcat->term_id); ?>”><?php echo … Read more