0
我需要在wordpress中的帖子內容後鏈接最後5個相同類別的帖子。任何人都可以幫助我?謝謝wordpress - 帖子頁面上的同一類別的其他帖子
我需要在wordpress中的帖子內容後鏈接最後5個相同類別的帖子。任何人都可以幫助我?謝謝wordpress - 帖子頁面上的同一類別的其他帖子
在循環之前聲明一些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; ?>
你可以使用WP_Query獲得你想要的信息。它非常靈活,你應該開始使用它。 它就像SQL查詢一樣。