|
发表于 2013-1-29 21:28:30
|
显示全部楼层
- <?php
3 l' w9 s& D3 N3 ^' E7 t: k5 x* v - //for use in the loop, list 5 post titles related to first tag on current post
a; t: r1 o7 Y' g* }& D: r) B - $tags = wp_get_post_tags($post->ID);2 Y) h$ N5 i/ i: d+ D5 \
- if ($tags) {* j; k, h% i) A. ^
- echo 'Related Posts';+ U8 H; G" ]% u$ |1 M2 O1 m
- $first_tag = $tags[0]->term_id;
$ j5 r0 ^' Z7 t/ e - $args=array( F: y6 p9 L# `8 ?7 B6 E# C1 E
- 'tag__in' => array($first_tag),, v& `: v, e6 |: o+ ?8 e/ `( K5 w3 K
- 'post__not_in' => array($post->ID),
( _( m) F8 K, ~% Z" G - 'showposts'=>5,
- \0 y/ y, c1 Y" L% P% { - 'caller_get_posts'=>1
7 ~- ^6 ^& a+ o- o# j - );) H" m8 ^/ L( s) i5 D( Y
- $my_query = new WP_Query($args);
' ?) K+ o' J+ a. n* K( i6 W- ~ - if( $my_query->have_posts() ) {
" ?5 F, w9 ]0 p7 w8 g# `0 {2 k - while ($my_query->have_posts()) : $my_query->the_post(); ?>! ?4 `' L* l) T! C
- <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
% I7 B l4 ~& h& |' c% @( U - <?php* j& o' i& H$ ?2 R1 d6 |
- endwhile;
e2 I o7 A# i( o: f! V - }
' _1 {& k0 x% ` - }
+ R# c' ^- s. S. C - ?>
复制代码 根据当前文章的第一个tag,显示5篇related posts。 |
|