|
|
发表于 2013-1-29 21:28:30
|
显示全部楼层
- <?php3 V& u5 q: u! S$ A6 y
- //for use in the loop, list 5 post titles related to first tag on current post
, q+ z$ ?" X" R - $tags = wp_get_post_tags($post->ID);; p1 T, J1 Z @8 J( T: j
- if ($tags) {
% b J. h, \! ]1 R5 ^% s! _+ [$ M8 i - echo 'Related Posts';; e% [, j0 R8 F, f
- $first_tag = $tags[0]->term_id;$ R$ _- c" T- Z
- $args=array(8 Q. I! k5 D- V& \
- 'tag__in' => array($first_tag),) J9 i5 P; y5 L( D* D2 c3 M
- 'post__not_in' => array($post->ID),3 R$ c& x3 S7 x+ z4 n8 ]' c3 }
- 'showposts'=>5,* i7 ?2 K. B9 G, Q$ B
- 'caller_get_posts'=>1
% B# Y/ D" S, Z" h A$ j - );
9 @5 g% w* K. O$ D/ C - $my_query = new WP_Query($args);
0 c7 P# t) _6 O - if( $my_query->have_posts() ) {$ L0 d4 n& q- s& k. ~8 V; q) W
- while ($my_query->have_posts()) : $my_query->the_post(); ?>
3 E5 Y0 }# b( d - <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>0 Z! ?, B+ E: @# q
- <?php. o* x; M6 y+ j& G" ~4 j$ W; n4 v/ R
- endwhile;. T: w6 s" S4 E; N. Q2 Z
- }
/ [5 `. n) f- s M! D" S% w+ G - }
% ~/ W7 x1 O; G8 y+ D4 e - ?>
复制代码 根据当前文章的第一个tag,显示5篇related posts。 |
|