Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/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
Wordpress WP_查询重复帖子_Wordpress - Fatal编程技术网

Wordpress WP_查询重复帖子

Wordpress WP_查询重复帖子,wordpress,Wordpress,我在wordpress主题中使用了wp_查询。 我在我的主页上有重复的帖子。 如何解决这个问题?这个问题与什么有关 整个悖论是,如果您将此代码作为单独的模板使用,那么一切都可以正常工作。如果你在一个模块中嵌入主题,那么所有的帖子都会按顺序排列。然后再次(1,2,3,4,5,1,2,3,4,5) 谢谢 } function render() { ob_start(); ?> <?php $custom_query =

我在wordpress主题中使用了wp_查询。 我在我的主页上有重复的帖子。 如何解决这个问题?这个问题与什么有关

整个悖论是,如果您将此代码作为单独的模板使用,那么一切都可以正常工作。如果你在一个模块中嵌入主题,那么所有的帖子都会按顺序排列。然后再次(1,2,3,4,5,1,2,3,4,5)

谢谢

}

function render() {
    ob_start();
    ?>               
           <?php $custom_query = new WP_Query('posts_per_page= 1');
             while($custom_query->have_posts()) : $custom_query->the_post();
                    ?>
              <div class="post-1">
                <div <?php post_class(); ?> id="post-<?php the_ID(); ?>">          
                  <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> </h3>    
                     <div class="float-tags">          
                                    <div class="bb-td-post-small-box clearfix">        
                                      <?php the_tags('','',''); ?>
                                    </div>
                     </div>
                  <div class="post-2">                                            
                    <?php the_content(); ?>    
                  </div>

                </div>
              </div>  

             <?php endwhile; ?>  
             <?php wp_reset_postdata(); // reset the query ?>


    <?php return ob_get_clean();
}
}
}
函数render(){
ob_start();
?>               

通过这种方式,您将始终获得一篇文章,该文章将在代码中重复调用render函数的次数。如果希望每次都显示不同的文章,则必须在WP\u QUERY中指定文章的偏移量。 参考:[偏移] 注意:在PHP中的行为类似于限制


希望它能对您有所帮助。

通过这种方式,您将始终获得一篇文章,该文章将在代码中重复调用render函数的次数。如果希望每次都显示不同的文章,则必须在WP\u QUERY中指定文章的偏移量。
<?php

function render($offset,$posts_per_page) 
{
    ob_start();
    $args['offset']=$offset;
    $args['posts_per_page']= $posts_per_page;
    $custom_query = new WP_Query($args);
    while($custom_query->have_posts()) : $custom_query->the_post();

?>
              <div class="post-1">
                <div <?php post_class(); ?> id="post-<?php the_ID(); ?>">          
                  <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> </h3>    
                     <div class="float-tags">          
                                    <div class="bb-td-post-small-box clearfix">        
                                      <?php the_tags('','',''); ?>
                                    </div>
                     </div>
                  <div class="post-2">                                            
                    <?php the_content(); ?>    
                  </div>

                </div>
              </div>  

             <?php endwhile; ?>  
             <?php wp_reset_postdata(); // reset the query ?>


    <?php return ob_get_clean();
}
render(0,5); //shows first 5,  0 to 5
render(5,5); //shows second 5,  5 to 10
render(5,5); //shows third 5,  10 to 15
参考:[偏移] 注意:在PHP中的行为类似于限制

希望它能帮助您。


<?php

function render($offset,$posts_per_page) 
{
    ob_start();
    $args['offset']=$offset;
    $args['posts_per_page']= $posts_per_page;
    $custom_query = new WP_Query($args);
    while($custom_query->have_posts()) : $custom_query->the_post();

?>
              <div class="post-1">
                <div <?php post_class(); ?> id="post-<?php the_ID(); ?>">          
                  <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> </h3>    
                     <div class="float-tags">          
                                    <div class="bb-td-post-small-box clearfix">        
                                      <?php the_tags('','',''); ?>
                                    </div>
                     </div>
                  <div class="post-2">                                            
                    <?php the_content(); ?>    
                  </div>

                </div>
              </div>  

             <?php endwhile; ?>  
             <?php wp_reset_postdata(); // reset the query ?>


    <?php return ob_get_clean();
}
render(0,5); //shows first 5,  0 to 5
render(5,5); //shows second 5,  5 to 10
render(5,5); //shows third 5,  10 to 15



你的数据库中有重复的数据吗?重复发布my houmepage,查看屏幕快照你能发送你的管理仪表板[发布列表和页面列表]部分的屏幕快照吗?你的数据库中有重复的数据吗?重复发布my houmepage,查看屏幕快照你能发送你的管理仪表板的屏幕快照吗[发布列表和页面列表]部分。请提供更多详细信息,好吗?我不太明白。如果我做了“每页帖子=5”,则显示5篇帖子,然后再次显示5篇帖子。请看,您需要给出下次的开始索引,它将以0作为开始索引,并从0开始显示5篇帖子。您下次需要更改它,例如0+5=5之类的内容检查下一个答案可以吗请再详细一点,好吗?我不太明白。如果我做了“posts\u per\u page=5”,那么将显示5篇文章,然后再次显示5篇文章。请看,您需要给出下次的开始索引,它将以0作为开始索引,并从0开始显示5篇文章。您下次需要更改它,例如0+5=5之类的内容检查下一个答案空白页,仅显示标题整个悖论是,如果你把这段代码作为一个单独的模板使用,那么一切都能正常工作。如果你在一个模块中嵌入主题,那么所有的帖子都会按顺序排列。然后再重复(1,2,3,4,5,1,2,3,4,5)@Ivan很抱歉,我无法理解此评论。如果您使用此代码,则页面上没有帖子。只需删除行“ob_start();”和“return ob_get_clean();”你会得到结果的。我刚刚测试了代码,如果删除了,我会工作。你可以说你的邮件,我会写你登录并通过。空白页,只有页眉和页脚。整个悖论是,如果你使用这个代码作为一个单独的模板,那么一切都会工作。如果你在一个模块中嵌入主题,那么所有的帖子都会按顺序进行。然后再次(1,2,3,4,5,1,2,3,4,5)。@Ivan我真的很抱歉,我无法理解这条评论。如果你使用此代码,页面上没有帖子。只需删除行“ob_start();”和“return ob_get_clean()”,你就会得到结果。我刚刚测试了代码,如果删除,我会继续工作。你可以说你的邮件,我会写你登录并通过。