给博客加上相关文章功能可以有效提高PV,也方便读者快速阅读。实现它很简单。可以用插件,推荐Yet Another Related Posts Plugin (YARPP),优点:
其核心功能无非是要实现相关文章匹配,一样可以用代码实现,而且是根绝文章标签判断,加载更快,也能自定义CSS样式。
<ol><?php $tags = wp_get_post_tags($post->ID); if ($tags) { $first_tag = $tags[0]->term_id; $args=array( 'tag__in' => array($first_tag), 'post__not_in' => array($post->ID), 'showposts'=>6, 'caller_get_posts'=>1 ); $my_query = new WP_Query($args); if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); ?> <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?> <?php comments_number(' ','(1)','(%)'); ?></a> </li> <?php endwhile; } } ?> </ol>
效果见本站各篇文章底部,如果有相关的标签即显示,没有的话为空。
可更改showposts的值,控制显示的数量,请自行测试。
谢谢收藏了
多多支持
烟哥,要实现两列显示该怎么弄呀?我好菜的,不懂呀