|
|
发表于 2013-1-29 21:28:30
|
显示全部楼层
- <?php
6 }- S9 H# X0 e. r- Z4 A( \: @ - //for use in the loop, list 5 post titles related to first tag on current post) K( Q" Y6 B7 g z& y8 r+ |3 t! ^
- $tags = wp_get_post_tags($post->ID);* U+ Q, @" G. M* E' J" v
- if ($tags) {( I+ c" D) z- w2 L) n4 L. d7 d! R3 g
- echo 'Related Posts';9 g' ], n- f+ u5 l5 ^' v% D& i
- $first_tag = $tags[0]->term_id;# i3 C; |3 Z, C( t8 T, {
- $args=array(; R4 i) D9 A/ C0 d! ]
- 'tag__in' => array($first_tag),
! \2 Y Z+ ^8 n$ ] - 'post__not_in' => array($post->ID),3 E# X: W, l4 }0 s
- 'showposts'=>5,
/ D2 q" d, x7 ?& t" ^- C3 X9 v - 'caller_get_posts'=>1% C" o; j7 d& t6 S& n+ |. U* B$ z
- );
) B( e' T2 Y% a - $my_query = new WP_Query($args);' v3 G" h" Y% ?
- if( $my_query->have_posts() ) {7 n6 R+ g5 c9 W: R
- while ($my_query->have_posts()) : $my_query->the_post(); ?>
& c2 E0 V) _; m( c( T" G$ v - <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
7 \ y9 E* ]5 N - <?php; y; O) A A$ W( g: Y
- endwhile;
8 E. ?+ j* T. L7 t$ D - }
8 k. h. r# O0 U5 i" x& l! D, Z - }
0 ~$ k3 ]5 z8 r - ?>
复制代码 根据当前文章的第一个tag,显示5篇related posts。 |
|