|
发表于 2013-1-29 21:28:30
|
显示全部楼层
- <?php' x9 u( m" ~: t3 O+ D2 j5 `1 S4 i$ y
- //for use in the loop, list 5 post titles related to first tag on current post: t* y8 V: l$ i7 N" W
- $tags = wp_get_post_tags($post->ID);
1 n$ n0 n, j, w8 Q3 M( U; u - if ($tags) {% g" \$ b0 S5 L* d1 w% ?
- echo 'Related Posts';
, Y6 w4 z8 j- h! z: U; R1 m6 e - $first_tag = $tags[0]->term_id;
- b# J& U8 L7 o1 [( s& \' C - $args=array(0 e6 |' |: R# v# T' h$ Q
- 'tag__in' => array($first_tag),
' l# k* \! N& ? - 'post__not_in' => array($post->ID),
' D$ ^% q2 W% n5 I - 'showposts'=>5,
" g: l: i r: @- D3 g# `! p/ d* } - 'caller_get_posts'=>13 [% c: Y7 a& f+ }
- );0 ?/ t# { m# U
- $my_query = new WP_Query($args);
B. b: R8 [/ N8 V" M. \ - if( $my_query->have_posts() ) {
0 M* E9 R& T& I* Z) C - while ($my_query->have_posts()) : $my_query->the_post(); ?>
: }4 H+ |& C5 a - <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
) `& U* P K2 L/ D# ^ - <?php7 Z/ E/ }" s$ }+ Z0 y
- endwhile;
* o3 B) C% D3 T% s! B% i - }) w, N% A" ]$ D) N# J
- } e2 e9 A8 e- @* M1 q; W
- ?>
复制代码 根据当前文章的第一个tag,显示5篇related posts。 |
|