wordpress如何避免页面重复内容
用WordPress程序打造CMS主题的网站,需要在页面展示显示多个日志列表,包括推荐最新写的日志,或来自某些特定分类的日志。这时侯一些页面就会有很多重复内容。我们必须避免重复内容以免被搜索引擎惩罚。如何避免页面重复内容呢?
通常我们是通过多个循环来实现日志列表的。避免重复内容也从循环语句处入手。
撇开所有的格式和CSS问题,让我们假设我们想要有两个日志列表。其中一个将列出最新的10篇日志,另外一个将列出“featured”分类的最新一篇日志。我们避免某一日志重复出现在两个列表中。
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID;?>
<!– Do stuff… –>
<?php endwhile; ?>
<!– Do other stuff… –>
<?php if (have_posts()) : while (have_posts()) : the_post();
if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
<!– Do stuff… –>
<?php endwhile; endif; ?>
不知道讲清楚没有,可以看看我的演示>>
这是我用的代码:
<?php $my_query = new WP_Query('showposts=1&cat=4'); while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID;?>
<h2><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
<?php echo mb_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 300,"……");?><a href="<?php the_permalink() ?>">继续阅读</a>
<?php endwhile; ?>
</div>
<?php query_posts('showposts=19&cat=4,5'); ?>
<ul class="c2">
<?php if (have_posts()) : while (have_posts()) : the_post();
if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark” title=”<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; endif; ?>
</ul>
</div>
相关阅读: