|
发表于 2013-1-29 21:28:30
|
显示全部楼层
- <?php; ]0 i H) {4 S M, W( F3 b2 e9 \
- //for use in the loop, list 5 post titles related to first tag on current post
5 Z, j. }0 i' h: Z) Q7 C - $tags = wp_get_post_tags($post->ID); M$ z3 n* I) G# B5 r
- if ($tags) {
6 Z \1 n: Y( ]$ J z, P - echo 'Related Posts';
) ]: z" ]. T/ i% V& K0 u" s - $first_tag = $tags[0]->term_id;) g, M$ p7 V7 A& _
- $args=array(& D1 ?, {0 O- H' L, \" c
- 'tag__in' => array($first_tag),* ^& `% K) Y+ z. R5 @& ]) z* C
- 'post__not_in' => array($post->ID),
. K4 P& C0 g1 A; ?2 M- h - 'showposts'=>5,5 a% y- l/ I" X; L
- 'caller_get_posts'=>1
. \/ [5 w; H$ L - );
" e! {1 Q, h; d: x - $my_query = new WP_Query($args);
, \. X; ~7 o! ]0 r - if( $my_query->have_posts() ) {4 W( G; U6 v/ Z1 z4 ~! C+ f/ {
- while ($my_query->have_posts()) : $my_query->the_post(); ?>! [; \2 L1 a" b2 ]
- <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
4 x0 _# E; N; c# Y" r - <?php [8 J; [; ?# c/ ] S# ?; k& F
- endwhile;( h: r6 r6 H, ]" J0 `5 W
- }
6 x2 d ` h; b* n& v4 U2 L - }' T7 U" R' D0 p. I" L
- ?>
复制代码 根据当前文章的第一个tag,显示5篇related posts。 |
|