|
发表于 2013-1-29 21:28:30
|
显示全部楼层
- <?php
0 `; O0 y9 f$ @% \ e - //for use in the loop, list 5 post titles related to first tag on current post* B+ f6 g; Y6 k F2 `0 C4 F
- $tags = wp_get_post_tags($post->ID);
! B7 q% x2 e, Y: {/ U- I+ J - if ($tags) {
6 l7 K9 b) {! F5 @) i; t) J - echo 'Related Posts';
3 |0 X( f. `" U - $first_tag = $tags[0]->term_id;
1 N7 Q: {: \8 M/ D8 R - $args=array(4 C4 h( f/ X( D/ k; ]/ d
- 'tag__in' => array($first_tag),3 r# S; Z1 i4 p* u* n5 H! j5 G
- 'post__not_in' => array($post->ID),& t+ \5 s T1 A' }4 x5 m$ c
- 'showposts'=>5,# @& h; s! t9 A% z5 v% W$ ]3 l
- 'caller_get_posts'=>1
9 U N6 p( D$ w% ^ - );* C! _+ \ l) n
- $my_query = new WP_Query($args);: { _ ]- `0 z9 J0 ^; s
- if( $my_query->have_posts() ) {0 f1 E" F0 s& }
- while ($my_query->have_posts()) : $my_query->the_post(); ?>
6 S/ n* C0 F$ O$ H - <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
5 N# `) O2 c! k7 o6 o( \ - <?php, I! Q2 m, Y& C0 M3 D
- endwhile;$ b# O0 G1 W. M/ Q3 {
- }3 s5 H! ?2 R2 X/ q! S T6 L
- }
) n# K! t, T( m- t& t- k - ?>
复制代码 根据当前文章的第一个tag,显示5篇related posts。 |
|