|
|
发表于 2013-1-29 21:28:30
|
显示全部楼层
- <?php
3 U) ?& x d( y6 l' a- R6 f* U/ @ - //for use in the loop, list 5 post titles related to first tag on current post
& m: ?1 \$ ~; M7 {% b; f% M/ } - $tags = wp_get_post_tags($post->ID);
. i" c- n& A) f0 R% }. ^ - if ($tags) {5 I8 |7 i: `6 s! ]
- echo 'Related Posts';0 M( X K7 P+ L5 l/ X
- $first_tag = $tags[0]->term_id;9 M j3 w! W6 {6 H
- $args=array(% k4 A' d0 v7 P$ u( f2 L# h5 V
- 'tag__in' => array($first_tag),
; [1 c, ^. |) s - 'post__not_in' => array($post->ID),3 o/ d4 K; R/ A* U B
- 'showposts'=>5,
5 x; d. S5 t# P, o' R$ `- k - 'caller_get_posts'=>1% P8 ~: S& |) Y. P
- );
5 h6 I8 t" Y- n0 E - $my_query = new WP_Query($args);
2 |' G2 K& Z/ H, ~' H - if( $my_query->have_posts() ) {
7 ~* k8 G" R' z: Q6 L' G: J - while ($my_query->have_posts()) : $my_query->the_post(); ?>
- s' S' ~; q9 n: q# J9 z8 A) r - <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>9 z& v/ j* Q5 a9 Z
- <?php) f+ |, x: ^0 Z
- endwhile;( j) |# F$ u3 d
- }) J" n! j/ b) E- U
- }
5 q% E; R2 x$ ?& k8 D - ?>
复制代码 根据当前文章的第一个tag,显示5篇related posts。 |
|