|
发表于 2013-1-29 21:28:30
|
显示全部楼层
- <?php; U) ~% i% H9 D; j" v; U8 K7 f
- //for use in the loop, list 5 post titles related to first tag on current post. E3 T! J j3 E7 I$ z" f
- $tags = wp_get_post_tags($post->ID);$ w$ Z+ C5 }9 i
- if ($tags) {0 J8 k1 q8 D5 G) O3 h: @
- echo 'Related Posts';
0 h; P" a# u8 o - $first_tag = $tags[0]->term_id;* ^& z. L* Y0 o0 ^4 ~& A6 r9 U6 p( ^
- $args=array(9 a1 W7 ^8 m3 Z9 K; U% X) t
- 'tag__in' => array($first_tag),
$ T* c' c- C, @5 V. J1 t - 'post__not_in' => array($post->ID),
# m/ G1 Q5 k, M' q6 w# j - 'showposts'=>5,
* ~+ s# X: c, P1 i - 'caller_get_posts'=>16 R* J) @, a% E
- );
# a1 k' E: V* B - $my_query = new WP_Query($args);
/ U5 c- y# `1 J7 R+ A. x - if( $my_query->have_posts() ) {
( h# z6 Y; v8 L" D - while ($my_query->have_posts()) : $my_query->the_post(); ?>
- T4 r0 @9 W3 G, ?7 d* [5 w - <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>7 b9 O9 s% b# b5 f
- <?php
/ U/ v3 }7 ^7 j& G$ \- `8 g H - endwhile;
4 E4 ^* S h' r+ F1 p - }
7 u4 x6 @& \! ~ - }
( Z6 E4 f1 r8 M1 g - ?>
复制代码 根据当前文章的第一个tag,显示5篇related posts。 |
|