Yet Another Related Posts Plugin(YARPP) 插件会自动提取和本页面相关的博客,显示出来。不过效果,在月小升的博客里不是特别的好。
采用自定义办法吧。
直接和tag相关的文章都展示出来。
将一下代码插入wordpress模板文件single.php文件下<?php the_content(); ?>后面即可。
-
global $post;
- $post_tags = wp_get_post_tags($post->ID);
- if ($post_tags) {
- foreach ($post_tags as $tag)
- {
- // 获取标签列表
- $tag_list[] .= $tag->term_id;
- }
- // 随机获取标签列表中的一个标签
- $post_tag = $tag_list[ mt_rand(0, count($tag_list) - 1) ];
- // 该方法使用 query_posts() 函数来调用相关文章,以下是参数列表
- $args = array(
- 'tag__in' => array($post_tag),
- 'category__not_in' => array(NULL), // 不包括的分类ID
- 'post__not_in' => array($post->ID),
- 'showposts' => 6, // 显示相关文章数量
- 'caller_get_posts' => 1
- );
- query_posts($args);
- if (have_posts()) :
- while (have_posts()) : the_post(); update_post_caches($posts); ?>