Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在单篇文章页面上显示最近的文章并排除活动的单篇文章_Php_Jquery_Wordpress - Fatal编程技术网

Php 在单篇文章页面上显示最近的文章并排除活动的单篇文章

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(); ?> &

我正在开发一个关于wordpess的网站

我有一个页面显示所有的新闻标题(帖子标题)。 当点击一个标题时,我会被引导到单篇文章页面。 我想在每个贴子页面的底部显示5个最近的贴子标题。 使用此代码可以很好地工作

<?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'
';您好,谢谢@kuldip Makadiya您的回答,但我不明白我的代码应该更改什么。。。我不是很熟悉php。。。谢谢你的帮助@Vickey。。。我不知道在哪里添加此代码,我不太熟悉php。。。这是JSFIDLE,你能帮我吗?我现在更新了代码,你可以在以前使用iThanks@Vickey的地方替换它。。。但我有个错误。。。它在第2416行的/HOMEZ.743/ROCKONBO/WWW/WP-INCLUDES/QUERY.PHP中显示:警告:数组#MAP()[FUNCTION.ARRAY-MAP]:参数#2应该是一个数组。警告:内爆()[FUNCTION.inclode]:在第2416行的/HOMEZ.743/ROCKONBO/WWW/WP-INCLUDES/QUERY.PHP中传递的参数无效添加WP#reset#QUERY()在这段代码结束后,我仍然会得到相同的错误…警告:ARRAY#MAP()[FUNCTION.ARRAY-MAP]:参数#2应该是第2416行/HOMEZ.743/ROCKONBO/WWW/WP-INCLUDES/QUERY.PHP中的数组警告:inpode()[FUNCTION.inpode]:第2416行/HOMEZ.743/ROCKONBO/WWW/WP-INCLUDES/QUERY.PHP中传递的参数无效