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.

Related posts

1 comment

  1. Just use WordPress’ function the_category. The second parameter single ensures that only child categories are shown. You can find more details about it in the documentation.
    It should work, if you use the code below in your while loop.

    <?php
     $postID = get_the_ID();
    
     the_category(', ', 'single', $postID);
    ?>
    

    I hope this helps.

Comments are closed.