我将这段代码显示为单代码。php模板
<ul class="cat-wrap">
<?php
global $post;
$categories = get_the_category();
foreach ($categories as $category) :
?>
<h5>same from <?php echo $category->name; ?></h5>
<?php
$args = array(
\'numberposts\' => 5,
\'category\' => $category->term_id,
\'post__not_in\' => array( $post->ID )
);
$posts = get_posts($args);
foreach($posts as $post) :
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>
<li><a href="<?php echo get_category_link($category->term_id);?>" title="View all posts filed under <?php echo $category->name; ?>">جميع مقالات قسم <?php echo $category->name; ?></a></li>
<?php endforeach; ?>
</ul>
循环工作正常,除了
\'post__not_in\' => array( $post->ID )
行为怪异。如果我有一篇分享4个不同类别的帖子,我会解释更多。生成的代码如下
<ul>
<h5>same from Cat1</h5>
<li>another article 1</li>
<li>another article 2</li>
<li>another article 3</li>
<li>another article 4</li>
<h5>same from Cat2</h5>
<li>Current Article</li>
<li>another article 1</li>
<li>another article 2</li>
<li>another article 3</li>
<h5>same from Cat3</h5>
<li>Current Article</li>
<li>another article 1</li>
<li>another article 2</li>
<li>another article 3</li>
<h5>same from Cat4</h5>
<li>Current Article</li>
<li>another article 1</li>
<li>another article 2</li>
<li>another article 3</li>
就像你只能注意到<h5>same from Cat1</h5>
不包括当前帖子,其余的包括它,不包括其他一些随机帖子。
提前谢谢,我希望我能解释我的问题。