2011-03-28 214 views

回答

0

在循環之前聲明一些var將保存post類別。比查詢與該貓的帖子。

這裏是例如:

<?php 
$cat_id = 0; // declare var 
if(have_posts()): 
    while(have_posts()): 
    // do what you usually do 
    $cat_id = $post->post_category; 
    endwhile; 
endif; 

// here you will get posts and make html output 
$last_in_cat = get_posts('posts_per_page=5&cat='.$cat_id); 
foreach($last_in_cat as $cat_post): 
?> 
<a href="<?php $cat_post->guid ?>"><?php $cat_post->post_title ?></a> 
<?php endforeach; ?> 
0

你可以使用WP_Query獲得你想要的信息。它非常靈活,你應該開始使用它。 它就像SQL查詢一樣。

相關問題