Wordpress提示和技巧:避免重复帖子

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Wordpress提示和技巧:避免重复帖子相关的知识,希望对你有一定的参考价值。

  1. <?php
  2. /* Start non-duplicates */
  3. function post_strip($where) {
  4. global $myPosts, $wpdb;
  5. $where .= " AND $wpdb->posts.ID not in($myPosts) ";
  6. return $where;
  7. }
  8. ?>
  9. <?php
  10. global $myPosts;
  11. $myPosts = '';
  12. ?>
  13. <div>
  14. <?php
  15. $my_query = new WP_Query();
  16. $my_query->query('showposts=5');
  17. if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post(); ?>
  18. <?php $myPosts .= $post->ID . ","; ?>
  19. <div><?php the_title(); ?></div>
  20. <!-- Post Stuff -->
  21. <?php endwhile; endif; ?>
  22. </div>
  23. <?php $myPosts .= "0" ?>
  24. <?php add_filter('posts_where', 'post_strip'); ?>
  25. <div><br/>
  26. <?php //$my_query = new WP_Query('category_name=Life&showposts=15');
  27. $my_query = new WP_Query('showposts=5');
  28. while ($my_query->have_posts()) : $my_query->the_post();?>
  29. <div><?php the_title(); ?></div>
  30.  
  31. <!-- Post Stuff -->
  32.  
  33. <?php endwhile; ?>
  34. </div>
  35. <?php remove_filter('posts_where', 'post_strip'); ?>
  36. <?php /* End non-duplicates */ ?>

以上是关于Wordpress提示和技巧:避免重复帖子的主要内容,如果未能解决你的问题,请参考以下文章

Wordpress:如何以编程方式创建帖子并在之前检查重复项

WordPress小部件中的重复表单字段?

如何避免帖子因条件而被移至垃圾箱?

使用 ajax 的重复帖子加载更多 wordpress

Wordpress 从循环中排除重复的 $sticky 帖子

HTML表单提交未在Wordpress帖子中调用Javascript“onsubmit”处理程序[重复]