我有一個功能,顯示所有帖子下相同的自定義分類稱爲「問題」。我需要對其進行調整,以便將其進一步縮小爲僅顯示同一類別下的帖子。WordPress:顯示當前類別的其他帖子
我看了一下WordPress的get_the_category()函數,但沒有太多的運氣。
下面是代碼:
<?php
$issueid = get_the_term_list($post->ID, 'issue', '', ', ', '');
$postslist = get_posts("numberposts=100&issue=$issueid");
foreach ($postslist as $post) :
setup_postdata($post); ?>
<div class="sidebar-box">
<div class="sidebar-left">
<p><a href="<?php echo get_page_link($page->ID) ?>"><?php the_title(); ?></a></p>
<p><?php the_date(); ?></p>
</div>
<div class="sidebar-right">
<?php echo get_the_post_thumbnail($page->ID, 'thumbnail'); ?>
</div>
</div>
<?php endforeach; ?>
這會正確顯示當前類別ID:
<?php
$category = get_the_category();
echo $category[0]->cat_id;
?>
所以,我試圖編輯當前的類別ID內的第一批代碼,只顯示帖子但它仍然返回一切:
$category = get_the_category();
$categoryid = $category[0]->cat_id;
$issueid = get_the_term_list($post->ID, 'issue', '', ', ', '');
$postslist = get_posts("numberposts=100&issue=$issueid&category=$categoryid");
foreach ($postslist as $post) :
setup_postdata($post); ?>
這是get_the_category函數參考:http://codex.wordpress.org/Function_Reference/get_the_category
任何幫助將不勝感激。
感謝,
韋德
我對你的要求有點困惑。你想顯示自定義分類中的所有文章,還是隻想顯示只有一個指定問題的文章。 – 2013-09-27 06:23:02