2015-06-15 74 views
1

我需要呼應職位類別鏈接,所以這裏是我的查詢:獲取類別鏈接WordPress的

<?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(); 
    ?> 

和底部,我需要點擊「查看所有文章」,它應該重定向到後子類別列表。

+1

獲取帖子的ID並使用函數get_the_category(post_id)獲取類別,帖子可能屬於多個類別。從get_the_category()返回的對象中檢索類別id,現在使用函數get_category_link(cat_id)獲取類別鏈接 – WisdmLabs

回答

0

只需使用Wordpress的功能the_category。第二個參數single確保只顯示子類別。您可以在documentation中找到關於它的更多詳細信息。
如果你在while循環中使用下面的代碼,它應該可以工作。

<?php 
$postID = get_the_ID(); 

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

我希望這會有所幫助。