|
|
发表于 2013-1-29 21:28:30
|
显示全部楼层
- <?php& x: s A) f, A$ k
- //for use in the loop, list 5 post titles related to first tag on current post
6 w) S' f8 W. P; J1 @. E - $tags = wp_get_post_tags($post->ID);. W2 ?1 B! R5 @# U8 y, |
- if ($tags) {
- Z a J. z. V - echo 'Related Posts';
) U( b: U2 ^$ `: a, m - $first_tag = $tags[0]->term_id;3 B a* z( A k+ k! Q1 L5 b
- $args=array(0 l8 x" t, n* F7 a0 N1 h
- 'tag__in' => array($first_tag),- U+ `* p# O! W# ^
- 'post__not_in' => array($post->ID), B6 \$ k6 _7 |: j% u" v! t1 [ q; Z
- 'showposts'=>5,, N5 G% Z" ~3 R6 b: q$ F
- 'caller_get_posts'=>1
o, S$ E) {) \, H% v | - );
& O3 Q+ A, f& @ I% c% E: Y - $my_query = new WP_Query($args);1 P. y& B" L1 z
- if( $my_query->have_posts() ) {& c. e" Q& @4 ~8 P
- while ($my_query->have_posts()) : $my_query->the_post(); ?>; {% u$ P, q2 k
- <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
# A- G; [2 e6 [3 P/ S - <?php3 O/ v6 D% z& K5 W1 p! F
- endwhile;
9 ?) u+ I- ?: c; f - }
& B+ K& [) @' q - }. u- e" x$ K% s: N& \
- ?>
复制代码 根据当前文章的第一个tag,显示5篇related posts。 |
|