Php 在单篇文章页面上显示最近的文章并排除活动的单篇文章
我正在开发一个关于wordpess的网站 我有一个页面显示所有的新闻标题(帖子标题)。 当点击一个标题时,我会被引导到单篇文章页面。 我想在每个贴子页面的底部显示5个最近的贴子标题。 使用此代码可以很好地工作Php 在单篇文章页面上显示最近的文章并排除活动的单篇文章,php,jquery,wordpress,Php,Jquery,Wordpress,我正在开发一个关于wordpess的网站 我有一个页面显示所有的新闻标题(帖子标题)。 当点击一个标题时,我会被引导到单篇文章页面。 我想在每个贴子页面的底部显示5个最近的贴子标题。 使用此代码可以很好地工作 <?php $the_query = new WP_Query( 'showposts=5' ); ?> <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?> &
<?php $the_query = new WP_Query( 'showposts=5' ); ?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<?php the_time('y-m-d'); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php endwhile;?>
我想做的是排除我最近阅读的5篇文章中的活跃单篇,否则我的文章会显示两次
有人知道这是否可能,我怎样才能做到
谢谢你的帮助
$args = array('posts_per_page' => 5,
'post__not_in' => $post->ID
);
$the_query = new WP_Query( $args );
while ($the_query -> have_posts()) : $the_query -> the_post();
the_time('y-m-d');
the_title();
the_content();
endwhile; wp_reset_query(); ?>
将$post->ID传递给数组中的post\u not\u
id将获取当前帖子id您可以使用get\u post进行此操作 例如:
<?php
$post = get_post($id); //assuming $id has been initialized
setup_postdata($post);
// display the post here
the_title();
the_excerpt();
the_post_thumbnail();
wp_reset_postdata();
?>
我找到了一个解决方案,下面是代码:
<?php $args = $args = array(
'numberposts' => 5,
'offset' => 0,
'post__not_in' => array( $post->ID )
);
$myposts2 = get_posts($args);
$the_query = new WP_Query( $args );
while ($the_query -> have_posts()) : $the_query -> the_post();?>
<div class="news">
<?php the_post_thumbnail('full'); ?>
<?php the_time('y-m-d'); ?>
<?php the_title(); ?>
<?php the_content(); ?>
</div>
<?php endwhile; wp_reset_query(); ?>
谢谢大家的帮助添加WP_查询('showposts=5&orderby=asc')//包括WP-load'er Include('WP-load.php');//获取最后10篇文章//以数组形式返回文章,而不是获取文章的对象$recent\u posts=wp\u Get\u recent\u posts(数组('numberposts'=>10));//用它们做点什么回音“
- ”;foreach($post作为$post){echo'';}echo'