|
发表于 2013-1-29 21:28:30
|
显示全部楼层
- <?php
; x, g0 V: G2 z) O - //for use in the loop, list 5 post titles related to first tag on current post# y" P6 A6 u7 U; b
- $tags = wp_get_post_tags($post->ID);& B& B1 o W5 z& v
- if ($tags) {0 n* C; W3 J. [+ Y8 o
- echo 'Related Posts';
) }1 ~- u% s C9 J# \ - $first_tag = $tags[0]->term_id;( ~4 O( }" E% P/ y& F8 U/ R
- $args=array(" \ u3 o4 h* m" {
- 'tag__in' => array($first_tag),4 G. F0 }# I# j1 V+ ~/ L( a
- 'post__not_in' => array($post->ID),. A" l: l# K4 m0 h
- 'showposts'=>5,
; G( I7 S9 B& o/ } - 'caller_get_posts'=>1
# n# B5 N; d: { - );& `" y8 H2 M! u' \" @
- $my_query = new WP_Query($args);" \# u" B5 h3 N# n
- if( $my_query->have_posts() ) {
1 _( E9 `* U5 t8 n( P - while ($my_query->have_posts()) : $my_query->the_post(); ?>) I/ H. }" e9 S" E9 K
- <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>, n) c4 |- P; j
- <?php
% J! Q) W/ p3 V& x; v: f8 u+ p' [$ ~ - endwhile;
; o4 K/ A% d& F% M8 e4 E0 U - }
) n: }+ _5 O! h {( f) Z& b+ F9 N - }% ?, v2 s9 S- h. g! \! V) N
- ?>
复制代码 根据当前文章的第一个tag,显示5篇related posts。 |
|