|
|
发表于 2013-1-29 21:28:30
|
显示全部楼层
- <?php t* b; ?" Y& m% E
- //for use in the loop, list 5 post titles related to first tag on current post
7 h% z8 ]% e# n x/ H { - $tags = wp_get_post_tags($post->ID);
( A' }) ]0 S6 o4 N - if ($tags) {: H4 ?) d& `0 }4 R/ W& V S
- echo 'Related Posts';8 ~/ X/ O+ J) W
- $first_tag = $tags[0]->term_id;
* i8 D* t3 K# Z: Z9 g3 g* B - $args=array(
5 K3 C' v9 p: |0 T) R4 R9 j" d - 'tag__in' => array($first_tag),9 x1 u5 M- e- z4 r' a2 o/ ?
- 'post__not_in' => array($post->ID),
% J: P# o9 p3 D. R - 'showposts'=>5,( u3 Y, r+ l# c* q) [
- 'caller_get_posts'=>1; d! T, k, p" h5 i* T
- );
7 o4 {; A: @& ]" D3 J - $my_query = new WP_Query($args);
# H4 c. x1 p+ @2 E5 H - if( $my_query->have_posts() ) {/ |) Z" Z+ i2 d3 ^. a0 N9 w
- while ($my_query->have_posts()) : $my_query->the_post(); ?>
% M$ Y( P" A% s' K* j - <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>! Y6 ?. N& H. r" N. D
- <?php
7 d" B2 J: t, T# q1 s- e - endwhile;! ~$ h# b: G5 Y/ n I
- }
0 e; `" Z5 L1 ?/ F - }/ h# ]+ q+ \) @& c4 ?6 ]0 |
- ?>
复制代码 根据当前文章的第一个tag,显示5篇related posts。 |
|