|
|
发表于 2013-1-29 21:28:30
|
显示全部楼层
- <?php: h+ l0 F% j& K3 v2 ?( F) U' K* b
- //for use in the loop, list 5 post titles related to first tag on current post
% h8 v5 K5 A! T& d, E8 g, `; v# p - $tags = wp_get_post_tags($post->ID);& a' N2 a. q: {. ?3 ]
- if ($tags) {5 F7 U5 X* ]' ~! J5 ^4 \* f6 \1 a
- echo 'Related Posts';
$ A3 a) q! P/ Z F( N, D" |7 P - $first_tag = $tags[0]->term_id;, S: ~) T! `' Q7 E, k4 H
- $args=array(
6 T+ j0 U9 o4 [& j6 \! B - 'tag__in' => array($first_tag),
* K& Z. d& C+ u, {& ]1 I* w$ F. V - 'post__not_in' => array($post->ID),
% X2 G. D& z% a0 e0 s1 G6 z( t - 'showposts'=>5,
# [* c9 O i7 `6 P; |0 m/ Q+ p5 r+ } - 'caller_get_posts'=>14 m6 a" v; x h, L) N: i/ Y/ ~ {
- );4 W; j$ L0 a% I- C# V
- $my_query = new WP_Query($args);
# c% N2 `" M7 s - if( $my_query->have_posts() ) {! M& J& L# a1 v! E, ?. c* _0 y' P
- while ($my_query->have_posts()) : $my_query->the_post(); ?>- g) B9 W+ K, ^
- <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
e ]4 Y$ o- Y) m - <?php
) `9 r. A' I$ J) P3 c1 T - endwhile;
0 A, d$ N& a6 Q8 T$ o; Y } - }
) ~& l3 x) D) L t - }9 z' @* p8 u, X" g
- ?>
复制代码 根据当前文章的第一个tag,显示5篇related posts。 |
|