我即将为新闻视图自定义模板。在由single.php
处理的文章中,我添加了标题为“您也可能感兴趣”的部分,然后我显示2个随机博客帖子。
问题是我正在查看的文章也会显示在该部分中。有没有办法可以排除它?
如果您需要进一步的信息,请告诉我们。
<?php
$posts = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => $limit, 'category__in' => $categories_query, 'orderby' => 'rand', 'order' => $order, 'showposts' => 2 ) );
$elements = jevelin_option( 'post_elements' );
?>
<div class="container-fluid more-articles">
<h2>More interesting articles</h2>
<div class="row equal-height">
<?php while ( $posts->have_posts() ) {
$posts->the_post();
?>
<div class="col-xs-12 col-md-6 teaser-col">
<div class="row">
<div class="col-xs-12 col-md-6 article-teaser-picture">
<?php echo the_post_thumbnail(); ?>
</div>
<div class="col-xs-12 col-md-6 article-teaser">
<div class="article-teaser-text">
<h3>
<?php echo the_title(); ?>
</h3>
<?php the_excerpt(); ?>
</div>
<div class="sh-button-container sh-button-style-3">
<a href="<?php echo esc_url( get_permalink() ); ?>" class="sh-button sh-button-large sh-button-icon-left">
<span class="sh-button-icon">
<i class="ti-control-forward"></i>
</span>
<span class="sh-button-text">Read more</span>
</a>
</div>
</div>
</div>
</div>
<?php
}
?>
</div>
</div>
答案 0 :(得分:1)
$currentID = get_the_ID();
将此行添加到WP_Query
'post__not_in' => array($currentID)