例如,我有一些類別包含5個帖子。當我選擇帖子時,需要顯示其所在類別的其餘四個帖子。如何在single.php上顯示此single.php所在類別的所有帖子
<?php
$infocat = get_the_category();
$info = $infocat[0]->cat_ID;
$array = "orderby=rand&showposts=10&cat=$info";
query_posts($array);
if (have_posts()) : while (have_posts()) : the_post(); ?>
<a class="permlinccat" href="<?php the_permalink() ?>" title="Перейти к посту: <?php the_title(); ?>" ><?php the_title(); ?></a>
<?php endwhile; else: ?>
<?php endif; wp_reset_query(); ?>
嘗試這個功能 - 幾乎是好的,但它只能得到職位
找到了解決的稱號......
<?php
$categories = get_the_category($post->ID);
if ($categories) {
$category_ids = array();
foreach($categories as $individual_category) $category_ids[] = $individual_category- >term_id;
$args=array(
'category__in' => $category_ids,
'post__not_in' => array($post->ID),
'showposts'=>5 //
);
$my_query = new wp_query($args);
if($my_query->have_posts()) {
echo '<h3>Current category</h3><ul>';
while ($my_query->have_posts()) {
$my_query->the_post();
?>
<a href="<?php the_permalink() ?>" rel="bookmark" title=" <?php the_title_attribute(); ? >"><?php the_title(); ?>
<img src="<?php echo first_image() ?>"title="<?php the_title(); ?>" alt="<?php the_title(); ?>"/>
</a>
<?php
}
echo '</ul>';
}
}
?>
向我們展示您已嘗試的當前代碼。 –
如果您想要整個發佈內容,則需要添加the_content()。 – enapupe