简体   繁体   English

获取类别链接wordpress

[英]get category link wordpress

I need to echo category link of posts, so here is my query: 我需要回显帖子的类别链接,所以这是我的查询:

<?php
     $args=array(
          'cat' => 3,
          'post_type' => 'post',
          'post_status' => 'publish',
          'posts_per_page' => 3,
          'caller_get_posts'=> 1
        );
       $my_query = null;
       $my_query = new WP_Query($args);
       if( $my_query->have_posts() ) {
           while ($my_query->have_posts()) : $my_query->the_post(); ?>

                ....SOME HTML....

        <?php
              endwhile;
         }
      wp_reset_query();
   ?>

And on the bottom I need button "Show all posts" and it should redirect to subcategory list of post. 在底部,我需要按钮“显示所有帖子”,它应该重定向到帖子的子类别列表。

Just use Wordpress' function the_category . 只需使用Wordpress'函数the_category The second parameter single ensures that only child categories are shown. 第二个参数single确保仅显示子类别。 You can find more details about it in the documentation . 您可以在文档中找到有关它的更多详细信息。
It should work, if you use the code below in your while loop. 如果在while循环中使用下面的代码,它应该可以工作。

<?php
 $postID = get_the_ID();

 the_category(', ', 'single', $postID);
?>

I hope this helps. 我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM