|
|
发表于 2013-1-29 21:28:30
|
显示全部楼层
- <?php$ z) l" ]! y, X3 \% g- L
- //for use in the loop, list 5 post titles related to first tag on current post
* m/ t# s- ^* i* j: i6 h) u - $tags = wp_get_post_tags($post->ID);. N8 P1 M. f# Q6 w( K2 E4 y+ r
- if ($tags) {* q( m2 _* b" b! w# r
- echo 'Related Posts';
4 h* r J' q" m7 f4 M9 h, M - $first_tag = $tags[0]->term_id;
# N |0 I! ~5 p - $args=array(
: [" G6 D4 k9 x0 R0 j/ Z - 'tag__in' => array($first_tag),) \9 Z1 R: ]. N2 l- L6 C
- 'post__not_in' => array($post->ID),
5 G. U! S6 B. q7 D5 C - 'showposts'=>5,, g, s- \ T# A0 e9 j
- 'caller_get_posts'=>1
Q+ ^1 h$ ]; G( r - );
7 T C4 C7 ~3 J - $my_query = new WP_Query($args);4 O- q5 @/ V$ K. S3 |0 H6 K. O3 `
- if( $my_query->have_posts() ) {
" @. F/ z$ a& E% Y/ Y# n* n - while ($my_query->have_posts()) : $my_query->the_post(); ?>
% |, N' w: X" D) C8 ?4 M- [( Z - <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
- g3 O, |5 j* \0 d+ y1 p8 c& x - <?php( ]* d" \0 L4 x0 @: I7 q! L
- endwhile;4 W2 u9 A, ~8 K7 q# k, W
- }
) [+ M/ }8 ]8 I' A+ b( Z - }
: B( k- u! x% \4 v- ?5 l9 L/ D - ?>
复制代码 根据当前文章的第一个tag,显示5篇related posts。 |
|