|
|
发表于 2013-1-29 21:28:30
|
显示全部楼层
- <?php* O! I; r, ^$ A+ a
- //for use in the loop, list 5 post titles related to first tag on current post
+ d2 \. h3 k* q" n |* o6 l - $tags = wp_get_post_tags($post->ID);) w6 B* D+ U* h- L, c
- if ($tags) {* g' f% w+ @) R6 w# ^
- echo 'Related Posts';
$ X0 i+ B1 z9 i3 ?8 r+ z - $first_tag = $tags[0]->term_id;
7 V2 E3 p! d4 G - $args=array(3 }4 M" r$ S1 {, e1 [
- 'tag__in' => array($first_tag),* Q1 f. N: S; G0 f5 c
- 'post__not_in' => array($post->ID),& B3 u* _( }, k9 `
- 'showposts'=>5,
- X( |# ~& }% L% B5 k - 'caller_get_posts'=>1
; q, R: _ f& l2 m/ ~1 J( n - );
( R q# e m+ ]) D, d* R( ^! B" M - $my_query = new WP_Query($args);- j, L) B* @* f# C& W$ T
- if( $my_query->have_posts() ) {8 _, g0 y* s$ f$ x+ ]) [
- while ($my_query->have_posts()) : $my_query->the_post(); ?>
1 W6 l" H N! d+ t$ b. S/ m3 p( P - <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
- ?9 r# P' Z3 ^& n - <?php" M! P' l3 H$ X! }/ H' V) `
- endwhile;
" W. E+ x: P0 U f3 P - }
0 `* H. C7 ~- ~ L - } S e; e6 A1 y0 M( K
- ?>
复制代码 根据当前文章的第一个tag,显示5篇related posts。 |
|