以下内容,都是版主亲自测试过有效才贴上来的,整理于网络
标签的使用标签有三个属性,一个是名称,一个是别名,一个是描述
1、调用当前文章所持标签的其他相关文章
- <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>
2、调用当前标签的描述
- <?php
- $tags = get_the_tags();
- foreach($tags as $tag) {
- $newtagdes.=$tag->description.",";
- }
- $newtagdes=rtrim($newtagdes, ",");
- echo $newtagdes;
- ?>
3、调用当前标签的别名
- <?php
- $tags = get_the_tags();
- foreach($tags as $tag) {
- $newtag.=$tag->name.",";
- }
- $newtag=rtrim($newtag, ",");
- echo $newtag;
- ?>
3、调用当前标签名称
- <?php the_tags('<strong>标签:</strong> ', ' , ' , ''); ?>