Made a custom cycle of outputting posts from the desired category on the main via wp_query.

Then he noticed that when you click on the label at the bottom of the post, WordPress displays all the posts of the category, and not specifically this label.

Same thing for query_posts.

When I put a normal cycle, everything is fine.

Cycle example:

<?php global $wp_query; $wp_query = new WP_Query(array( 'posts_per_page' => '10', 'post_type' => 'post', 'category__in' => '1', 'paged' => get_query_var('paged') ?: 1 )); while( have_posts() ) { the_post(); ?> <article class="post"> <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <div class="post__info"> <span class="post__info--date"><?php echo get_the_date(); ?></span> <span class="post__info--comments"><a href="<?php the_permalink(); ?>#comments">комментировать</a></span> </div> <?php the_content(); ?> <p class="post__hashtag"><?php the_tags($before=""); ?></p> </article> <?php wp_reset_postdata(); // reset the query ?> <?php } ?> 
  • "If the post has no tags, then the function will display a link to the category associated with the post." wp-kama.ru/function/the_tags - SeVlad
  • But posts have tags, that's just the point. - Konstantin Kapelnikov

1 answer 1

  <p class="post__hashtag"><?php the_tags($before=""); ?></p> 

The syntax is incorrect. If you want to remove the default label name something like this:

  <p class="post__hashtag"><?php the_tags(''); ?></p> 
  • No, it's about the cycle, I guess. He displays category 1 posts, and by clicking on the label at the end of the post, for example, the website.ru / tag / books, he again displays all posts of category 1, rather than posts labeled books ... - Konstantin Kapelnikov
  • Understood. Everything turned out to be so simple that it is already a shame. It was just necessary either to create a cycle separately in the home.php template for the main one, or a separate cycle in the tag.php template to display posts by tags. Otherwise, everything referred to index.php, where there is a cycle with coercion to display posts of one category. - Konstantin Kapelnikov