|
|
发表于 2013-1-29 21:28:30
|
显示全部楼层
- <?php+ I* t5 q3 }2 V z S4 T) t& A# f
- //for use in the loop, list 5 post titles related to first tag on current post; O/ z) w5 k/ n/ ^1 p0 W% f
- $tags = wp_get_post_tags($post->ID);7 ~' k) z0 P7 v/ b7 X
- if ($tags) {/ t V0 V+ @6 O2 Y
- echo 'Related Posts';7 }" ^" W2 P6 h2 P# H6 Q3 t
- $first_tag = $tags[0]->term_id;
& h" r$ o1 }$ ^( e( E- L7 V o - $args=array(
2 h2 f0 f" c% {4 {- h - 'tag__in' => array($first_tag),* {+ m0 S4 H/ \
- 'post__not_in' => array($post->ID),
5 D- H1 D/ [! f - 'showposts'=>5, U0 h& I+ I8 k, s
- 'caller_get_posts'=>1
% z' z' J, c9 @7 U) k% p1 ? - );
- H( L. c5 _4 a* `/ d* u - $my_query = new WP_Query($args);# b+ U% I- R6 i9 e
- if( $my_query->have_posts() ) {0 H% u# t# a$ W6 x
- while ($my_query->have_posts()) : $my_query->the_post(); ?>' ~5 X5 u' g3 `+ V% \% R# l
- <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>( x# Q/ E$ e; X
- <?php
% R# X7 s/ F4 @8 H - endwhile;1 L1 K9 t( A3 _9 ?6 S
- }7 z2 o2 h9 M# F2 L/ f: f& J
- }
$ Z+ u+ j) {* U" V. a - ?>
复制代码 根据当前文章的第一个tag,显示5篇related posts。 |
|