|
发表于 2013-1-29 21:28:30
|
显示全部楼层
- <?php
3 u5 D6 ~/ l7 G/ b8 f6 F - //for use in the loop, list 5 post titles related to first tag on current post4 \- n. j% M! h9 e5 |2 q
- $tags = wp_get_post_tags($post->ID);
; g" e, n! U# w - if ($tags) {3 A2 O+ T* u: g* h
- echo 'Related Posts';
/ X) A5 T7 Q6 ?5 ? - $first_tag = $tags[0]->term_id;& b6 H7 `5 Y1 H9 r! T
- $args=array(
* L3 q4 m" v& a4 H1 ]+ o& a" }+ E. G - 'tag__in' => array($first_tag),
- y# l3 X P. q+ Y8 k" f' x - 'post__not_in' => array($post->ID),% p$ _" |. n- k1 i
- 'showposts'=>5,' _8 j2 s* P. m9 E% L
- 'caller_get_posts'=>1
' F! U! F8 U* P. z q# } - );+ I2 {7 n0 b9 T( e
- $my_query = new WP_Query($args);
9 T: O8 ]' Z6 q/ J$ g* O - if( $my_query->have_posts() ) {
, w# f# s4 v7 v3 x1 Q$ m - while ($my_query->have_posts()) : $my_query->the_post(); ?>5 H4 m* m* D1 ^; E ]; N
- <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
9 w v; R' D) K( F p - <?php
0 @2 V) p1 M- o1 @ - endwhile;" M9 p9 G; p0 B. Z, u; |& i
- }
' `. {" j$ ~& |( L3 M - }/ W4 T u9 q) q! ~2 v
- ?>
复制代码 根据当前文章的第一个tag,显示5篇related posts。 |
|