|
|
发表于 2013-1-29 21:28:30
|
显示全部楼层
- <?php
8 W& C. C7 [$ \" w$ |. B - //for use in the loop, list 5 post titles related to first tag on current post
& t. K, J" m% @% N( I( z - $tags = wp_get_post_tags($post->ID);
6 K" R; _- w+ r - if ($tags) {( Y4 ?1 W: @1 i% h4 @
- echo 'Related Posts';
& O( R: E8 f: i! P# R+ x - $first_tag = $tags[0]->term_id;% Y2 ~4 [" a, x8 D' z: b
- $args=array(. u2 o( |3 Z. Q
- 'tag__in' => array($first_tag),# V3 p% h1 t8 W& y/ t7 K7 H* K
- 'post__not_in' => array($post->ID),8 K6 n3 @0 w7 g" }9 o% f' h% t
- 'showposts'=>5, c4 P& R$ q* I. p) m/ z4 ~5 ^! v0 h
- 'caller_get_posts'=>1
) m0 n8 M+ j9 R0 \: z9 a: j# P - );
. ]0 u2 l0 K3 \ - $my_query = new WP_Query($args);
1 y1 L7 T7 G3 w9 d$ ] - if( $my_query->have_posts() ) {3 z. A) [/ J3 V1 M9 T( h
- while ($my_query->have_posts()) : $my_query->the_post(); ?>. _/ c$ v4 i/ A8 c5 h( U& R
- <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
$ ?. Z" F6 z$ R& Q7 `7 e - <?php
$ X2 E9 t2 q" ?7 a8 _6 X - endwhile;
7 N1 y2 J3 i) ^1 O' B) _5 ] - }. _& v* e& Y* I; j
- }
$ n2 A$ Q$ G+ g4 a& P- J' U - ?>
复制代码 根据当前文章的第一个tag,显示5篇related posts。 |
|