Php 显示最近的博客文章,但排除当前文章
我想在我的博客页面底部显示最近的3篇文章,但不显示当前的文章 我的代码:Php 显示最近的博客文章,但排除当前文章,php,wordpress,Php,Wordpress,我想在我的博客页面底部显示最近的3篇文章,但不显示当前的文章 我的代码: <div class="blog__posts"> <h2><?php esc_html_e('andere blogberichten', 'dfib-theme'); ?></h2> <a href="<?php echo get_permalink( get_option( 'page_for_posts' ) ); ?>" class
<div class="blog__posts">
<h2><?php esc_html_e('andere blogberichten', 'dfib-theme'); ?></h2>
<a href="<?php echo get_permalink( get_option( 'page_for_posts' ) ); ?>" class="btn btn-overview"><?php esc_html_e('alle blogberichten', 'dfib-theme'); ?></a>
<div class="blog__posts--wrapper">
<?php
$the_query = new WP_Query( array(
'posts_per_page' => 2,
));
?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="blog__single">
<a href="<?php the_permalink(); ?>"><div class="blog__single--img" style="background-image: url(<?php echo get_the_post_thumbnail_url();?>);"></div></a>
<h2><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
<a href="<?php the_permalink(); ?>">lees meer</a>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php __('No News'); ?></p>
<?php endif; ?>
</div>
</div>
它显示3篇文章,但当我访问最近的文章时,相同的文章再次显示在底部。有没有办法每次都排除当前的问题?我刚刚在这个网站上找到了解决方案: 我刚刚在我的查询中添加了以下内容:
'post__not_in' => array(get_the_ID())
我刚刚在这个网站上找到了解决方案: 我刚刚在我的查询中添加了以下内容:
'post__not_in' => array(get_the_ID())
您必须使用中的
post\u not\u排除当前帖子
在WP\u查询数组中添加post\u not\u,如下所示
<?php
$the_query = new WP_Query( array(
'posts_per_page' => 2,
'post__not_in' => array( get_the_ID() )
));
?>
您必须用中的post\u not\u排除当前帖子
在WP\u查询数组中添加post\u not\u,如下所示
<?php
$the_query = new WP_Query( array(
'posts_per_page' => 2,
'post__not_in' => array( get_the_ID() )
));
?>