|
发表于 2013-1-29 21:28:30
|
显示全部楼层
- <?php7 t7 n0 H. ]9 J/ Q0 t3 \
- //for use in the loop, list 5 post titles related to first tag on current post$ ^3 r( W3 e1 f4 v
- $tags = wp_get_post_tags($post->ID);
8 ^4 ^) G+ ~1 B, H) P - if ($tags) {
' H5 z' ]5 l4 b8 Y0 G$ ^ - echo 'Related Posts';" P; v! y, l7 w- ^5 z$ k
- $first_tag = $tags[0]->term_id;
& r* t% f& V5 H* |' _& |1 U( G - $args=array(
! `+ q& `6 I) ~ i* M4 S - 'tag__in' => array($first_tag),
) ~8 ]1 t2 I8 F+ h- E/ Y/ Y# d - 'post__not_in' => array($post->ID),
% S- N) }( q7 u - 'showposts'=>5,
- M; G: K3 ]: T$ B - 'caller_get_posts'=>1$ f' \6 l" z6 T( ?, s
- );
7 ^0 V% Y: A: O% d - $my_query = new WP_Query($args);) _# F) h7 u5 Q; [+ O
- if( $my_query->have_posts() ) {9 E: s" B. |" ]& {4 c( h
- while ($my_query->have_posts()) : $my_query->the_post(); ?>
& | |, }' ?! O" |* M- e& ? - <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
# R/ H* `& t1 R. K - <?php
- ^6 I% z! H$ ^" N/ J - endwhile;
7 Q1 J6 R* h, }" y - }! E* I- g! l* f
- }
# o& ?& c9 j" L# z( ^4 Z- l. V% Q - ?>
复制代码 根据当前文章的第一个tag,显示5篇related posts。 |
|