|
发表于 2013-1-29 21:28:30
|
显示全部楼层
- <?php
, Y* ~" ]3 ?& }& Z' S) R - //for use in the loop, list 5 post titles related to first tag on current post
8 j; t2 f( S1 T - $tags = wp_get_post_tags($post->ID);
) S4 r3 a7 w/ D+ {5 d8 E$ u% d - if ($tags) {
6 F5 N" k. t$ ^5 n7 v - echo 'Related Posts';/ M C6 e9 p. p" c! l4 V8 p' ?
- $first_tag = $tags[0]->term_id;: Q9 h4 F- m$ I9 E" W# f4 y
- $args=array(
/ O. ^1 \0 i2 b) K - 'tag__in' => array($first_tag),
$ T6 I/ v2 T; i% s" e& i. V2 O8 ` - 'post__not_in' => array($post->ID),) @& f' N* I7 H# S. r" O
- 'showposts'=>5,
, g6 U; q, D0 a- c, P - 'caller_get_posts'=>1
: D) {1 D0 K( P& [3 c - );# \$ B% r1 I: O# r$ h$ L5 ?* v
- $my_query = new WP_Query($args);
* G j7 ^/ L; D4 F. R& ^ - if( $my_query->have_posts() ) {
2 _4 ]7 y: p1 U! a( } - while ($my_query->have_posts()) : $my_query->the_post(); ?>
7 d1 n8 P1 }3 Y o+ W v/ g - <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>, q& N2 A: y2 F8 X7 m; H3 W9 i9 Z* C8 {
- <?php2 T% @1 I5 a J
- endwhile;7 p( n d+ o0 u5 a2 T0 D9 W( V
- }) Q3 l) P. v& n( E+ E
- }/ f; a$ K4 u( e6 E$ _
- ?>
复制代码 根据当前文章的第一个tag,显示5篇related posts。 |
|