|
发表于 2013-1-29 21:28:30
|
显示全部楼层
- <?php
+ a6 K! v' ]* G: K - //for use in the loop, list 5 post titles related to first tag on current post
( q1 P9 r3 h) Z - $tags = wp_get_post_tags($post->ID);
6 g! d' H, g% E( p - if ($tags) {$ d8 R0 Y5 Q4 r( w( h8 L$ @
- echo 'Related Posts';' t' u; ]- P* Q; s7 \; h
- $first_tag = $tags[0]->term_id;( P9 \2 M+ _0 f. Q7 d! \
- $args=array(
' k6 ]2 ~' V1 N) e; D1 x) W2 T7 W - 'tag__in' => array($first_tag),
( g- X6 f1 _& D" y3 K9 F# C( T; o - 'post__not_in' => array($post->ID),
. E9 }2 J% W: Y0 b3 k - 'showposts'=>5,
/ |" B, R. H: p5 y, r - 'caller_get_posts'=>1
& U$ o8 z$ U3 U2 w* q5 x' }/ O - );1 J9 A1 q# w" ~" r; c. W* p
- $my_query = new WP_Query($args);
; E# v# q3 I1 y4 d' s# R! r: U - if( $my_query->have_posts() ) {
4 ^( i8 W- @6 X# S% l( p - while ($my_query->have_posts()) : $my_query->the_post(); ?>
" E+ a, b, A4 P( H! F - <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
0 Q, C$ h( c) b1 J+ S- J - <?php0 f8 C, o" P5 t( Z0 y
- endwhile;
- } s* G- b3 S- m& H v; v7 S - }4 c/ R' \" y6 @1 b$ o
- }! M; f- r4 L ^' x9 Y7 u. Y
- ?>
复制代码 根据当前文章的第一个tag,显示5篇related posts。 |
|