|
|
发表于 2013-1-29 21:28:30
|
显示全部楼层
- <?php3 g4 X1 V; ]/ x0 J. z4 ~
- //for use in the loop, list 5 post titles related to first tag on current post
7 q" f7 X" V, O; ? - $tags = wp_get_post_tags($post->ID);
6 }- F' {6 D8 _) H - if ($tags) {
: a: M- A8 T. N - echo 'Related Posts';& P# N# g% G, {8 j+ D( P
- $first_tag = $tags[0]->term_id;. g- \! V) L) _! [* k2 Y: g0 ]8 i& |0 g
- $args=array(7 D; j. L# P8 j, ]5 @) r5 d$ |
- 'tag__in' => array($first_tag),
) }4 E% p/ E v% F" ]2 G - 'post__not_in' => array($post->ID),
! f2 R( R3 @! X% ?4 R* i$ f - 'showposts'=>5,, X5 p$ k5 n$ P2 `, X% ]- C
- 'caller_get_posts'=>1
! C0 R5 O! g0 J; G* _+ L - );
: O! P7 Y9 [! e( _ - $my_query = new WP_Query($args);
& P7 Z/ e# b; w' k* x2 J - if( $my_query->have_posts() ) {
4 ^2 M2 S/ t, C- ? - while ($my_query->have_posts()) : $my_query->the_post(); ?>
# v; K- T, k$ }0 S) g+ U - <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
9 T+ Z! U2 z2 X4 z - <?php
/ w, J; J' Q' O - endwhile;: k' S8 d4 f. \* h c
- }
8 a2 [0 V$ A" t' I - }- o6 U3 m! J& l7 n# P8 s; g% a5 B
- ?>
复制代码 根据当前文章的第一个tag,显示5篇related posts。 |
|