|
发表于 2013-1-29 21:28:30
|
显示全部楼层
- <?php
* b# H( D+ L1 U; H. I - //for use in the loop, list 5 post titles related to first tag on current post
! d' f+ h# ^. q4 H; l( ^" z - $tags = wp_get_post_tags($post->ID);
, d6 ]+ F2 u+ ` P8 r - if ($tags) {
3 A4 |* z" n) o4 a( c9 W0 } - echo 'Related Posts';9 t1 _ ^5 R* N2 `8 f9 r1 {
- $first_tag = $tags[0]->term_id;
) U3 w4 C% ]2 _8 e - $args=array(
1 S& p6 d: z" a' d - 'tag__in' => array($first_tag),
9 d- ~8 T+ V+ }0 K" I - 'post__not_in' => array($post->ID),7 Z4 q, @3 M* A, W
- 'showposts'=>5,, Q4 ~) T; h& n4 ^
- 'caller_get_posts'=>1
+ `; a) N0 o r& M4 p - );) z$ F$ L4 P; r2 N
- $my_query = new WP_Query($args);- b5 r, B. F% Y9 t, f
- if( $my_query->have_posts() ) {$ q+ m9 m! b2 T8 i C1 Z4 \3 r
- while ($my_query->have_posts()) : $my_query->the_post(); ?>( J. K4 Y6 L. s' J" C: C: J; P
- <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
8 C) b {, Y& R6 N/ r' ] - <?php
2 L( B* B" Z' R- q( c7 C - endwhile;
$ y1 m! w2 m+ H/ M( ?8 |* a - }
0 N" K/ }. k( P; p6 Y" s - }$ b. k5 E# p! f: C8 P: |* q$ m
- ?>
复制代码 根据当前文章的第一个tag,显示5篇related posts。 |
|