|
发表于 2013-1-29 21:28:30
|
显示全部楼层
- <?php
' J: i* H) [ W: F/ ?5 O - //for use in the loop, list 5 post titles related to first tag on current post2 G, o& }% d, r/ o' l: q
- $tags = wp_get_post_tags($post->ID);1 t# \* ^# \+ k5 G
- if ($tags) {- I+ z9 A$ d. Z; v) m& h
- echo 'Related Posts';
! ?2 D0 H' u$ ]8 @& U - $first_tag = $tags[0]->term_id;
- {% L* P6 R- U5 W* J$ s' I - $args=array(/ Q9 t1 \" S3 Q" k- ?& K# A+ v
- 'tag__in' => array($first_tag),; x/ ]7 C3 I6 G0 _
- 'post__not_in' => array($post->ID),
0 k9 u' T% `9 g5 c2 R6 C+ T# @ - 'showposts'=>5,8 \- D5 t/ f" ~$ R- }2 O
- 'caller_get_posts'=>1+ Q1 _* w. G; C) p+ M( Z4 L
- );$ m: \, h* z( O0 |, K( f; C8 j
- $my_query = new WP_Query($args);2 t O7 g3 L( }2 L- M8 ~
- if( $my_query->have_posts() ) {8 D/ u+ a2 ?6 \4 |/ l u
- while ($my_query->have_posts()) : $my_query->the_post(); ?>
4 B, i' W" ?7 S3 a! ?" l - <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>0 {: _/ r# ]3 y9 X, D( a
- <?php
/ r7 X0 T8 s+ Q& d: C4 v% r$ ^ - endwhile;
5 b. S' T1 F4 m& z$ s9 J1 B4 F - }
4 T O" f% E1 m; a" k D - }
( ~$ ~. [7 f5 l5 f. b& Q - ?>
复制代码 根据当前文章的第一个tag,显示5篇related posts。 |
|