|
|
发表于 2013-1-29 21:28:30
|
显示全部楼层
- <?php/ {$ k: Y0 c: L1 e0 K9 U
- //for use in the loop, list 5 post titles related to first tag on current post. B4 Z" w. E; X% @
- $tags = wp_get_post_tags($post->ID);' a( ?6 C s) ^; f
- if ($tags) {
3 ]. ]! l& x# ?1 B" K' r8 G - echo 'Related Posts';% \4 {; T8 ^: s1 s- h. w# E
- $first_tag = $tags[0]->term_id;
3 j8 j6 R4 ]- h! J+ ~ - $args=array(
, i" \3 X% K) u/ Q: u6 J. c - 'tag__in' => array($first_tag),5 t3 L0 ^$ W6 Q& p( T
- 'post__not_in' => array($post->ID),: Y+ W" g* l C' Y- T
- 'showposts'=>5,% g' S4 R- w" e; ]8 }& f+ x
- 'caller_get_posts'=>1
1 I6 C6 f/ v; V$ ]( M - );
0 R6 [" `5 L( j& ?! L. I - $my_query = new WP_Query($args);4 ~5 R) [% K9 r/ I- @( c
- if( $my_query->have_posts() ) {
$ y, m) a, v# w/ G6 F - while ($my_query->have_posts()) : $my_query->the_post(); ?>0 C- h( ]7 q% U, @; {
- <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
4 v+ B+ K |8 D$ V0 i$ f& ]" Q - <?php
- A! `0 b4 \: i2 K6 e& y/ L - endwhile;' R' X! P$ q4 v$ d3 o2 w( P
- }0 k) h) O0 V6 Q8 s/ Z$ S4 V
- }
2 u. k9 g7 h7 K# d; ~& I9 L - ?>
复制代码 根据当前文章的第一个tag,显示5篇related posts。 |
|