|
|
发表于 2013-1-29 21:28:30
|
显示全部楼层
- <?php% b5 V2 ^6 S- P g4 p
- //for use in the loop, list 5 post titles related to first tag on current post
9 ?) ^* f( j t - $tags = wp_get_post_tags($post->ID);5 _: n" A7 d! ~
- if ($tags) {' ]! o4 r" e0 n0 d `! Z
- echo 'Related Posts';6 z4 T9 S$ S) D/ M9 F$ R6 v
- $first_tag = $tags[0]->term_id;
+ T, O% K- }, A ?$ T3 O* v - $args=array(% J3 Y# m# a( }9 v+ q% s8 P
- 'tag__in' => array($first_tag),
+ {* L4 K3 {$ Q: d7 d - 'post__not_in' => array($post->ID),
3 G, M( Q9 ?: f& y# j; u - 'showposts'=>5,
( w% v8 c$ u! T7 t8 Q - 'caller_get_posts'=>10 }# P) r4 P. q, g! U8 e% Z9 `; g
- );7 Q% M, |3 e: ?" y- n3 P2 V
- $my_query = new WP_Query($args);. U* t. K. }$ u+ D7 p4 I
- if( $my_query->have_posts() ) {
6 b: h; _" K \+ w2 p' b7 Y - while ($my_query->have_posts()) : $my_query->the_post(); ?>9 o5 V2 S% {! B% P2 T6 a3 R
- <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
V( `0 @6 c+ n7 y+ Z6 J/ B# j - <?php4 o2 l! d5 u( {5 \; I3 a+ R
- endwhile;* ]) v* y1 k4 v
- }- w) @3 u5 Q9 Q8 Z. u! F. n& e
- }
# z8 A1 K5 u: q) t# f - ?>
复制代码 根据当前文章的第一个tag,显示5篇related posts。 |
|