|
发表于 2013-1-29 21:28:30
|
显示全部楼层
- <?php
9 O% A& D. ]& }4 Q# l+ m - //for use in the loop, list 5 post titles related to first tag on current post( R7 h& E+ h* Q+ [* H1 j
- $tags = wp_get_post_tags($post->ID);$ E* ^! P: {4 r. y/ v
- if ($tags) {
T- R- r2 P/ P! [/ Y% h8 ^ - echo 'Related Posts';) [5 P% j& T" ]
- $first_tag = $tags[0]->term_id;! c& [8 B. s. r2 I1 D; U N9 r
- $args=array(, I7 _ `1 t K) V
- 'tag__in' => array($first_tag),
?& ~8 o( a; P+ O - 'post__not_in' => array($post->ID),3 f( F( i2 g1 ^4 G
- 'showposts'=>5,
# x' M' d6 F3 T4 V. w' W - 'caller_get_posts'=>1
$ w8 a5 G. x/ C5 N3 J: B3 E. W - );
- v# H3 o! q$ ^$ W: e# X( F - $my_query = new WP_Query($args);
# r" D& B# e7 n! N ^* v6 i - if( $my_query->have_posts() ) {1 v$ \ s/ P) C. ?, @) E; W
- while ($my_query->have_posts()) : $my_query->the_post(); ?># w) g, Y2 [; U8 ^9 ?
- <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>% d5 E) |0 C% t6 Q
- <?php
- V9 b. ?: ^1 W/ \ - endwhile;, ?' l$ }# x1 B% O8 u; h$ L
- }
7 e3 `! S- z, s- [6 { - }
4 `+ I8 b7 a7 e T& ^0 W' n# C3 O - ?>
复制代码 根据当前文章的第一个tag,显示5篇related posts。 |
|