Wordpress提示和技巧:避免重复帖子
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Wordpress提示和技巧:避免重复帖子相关的知识,希望对你有一定的参考价值。
<?php /* Start non-duplicates */ function post_strip($where) { global $myPosts, $wpdb; $where .= " AND $wpdb->posts.ID not in($myPosts) "; return $where; } ?> <?php global $myPosts; $myPosts = ''; ?> <div> <?php $my_query = new WP_Query(); $my_query->query('showposts=5'); if ($my_query->have_posts()) : while ($my_query->have_posts()) : $my_query->the_post(); ?> <?php $myPosts .= $post->ID . ","; ?> <div><?php the_title(); ?></div> <!-- Post Stuff --> <?php endwhile; endif; ?> </div> <?php $myPosts .= "0" ?> <?php add_filter('posts_where', 'post_strip'); ?> <div><br/> <?php //$my_query = new WP_Query('category_name=Life&showposts=15'); $my_query = new WP_Query('showposts=5'); while ($my_query->have_posts()) : $my_query->the_post();?> <div><?php the_title(); ?></div> <!-- Post Stuff --> <?php endwhile; ?> </div> <?php remove_filter('posts_where', 'post_strip'); ?> <?php /* End non-duplicates */ ?>
以上是关于Wordpress提示和技巧:避免重复帖子的主要内容,如果未能解决你的问题,请参考以下文章
Wordpress:如何以编程方式创建帖子并在之前检查重复项