很多朋友在做主题开发的时候,做到相关文章推荐的时候,不知道怎么调用,因为wp没有相关函数可以直接用,这里在网上收集了一个根据添加的标签,调取相关推荐的方法,废话不多逼到,直接上代码:

 <h3>相关文章</h3>
 <ul id="tags_related">
                <?php
                $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); ?>
                
  <li> <a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
  <?php endwhile; else : ?>
  <li>暂无相关文章</li>
  <?php endif; wp_reset_query(); } ?>
</ul>