|
|
发表于 2013-1-29 21:28:30
|
显示全部楼层
- <?php
& E7 M& |' u. R9 {$ c* x - //for use in the loop, list 5 post titles related to first tag on current post1 S9 b( U" v* @7 m: O, a$ ]' E1 _7 [5 o: M
- $tags = wp_get_post_tags($post->ID);
$ Y9 V$ {0 S- T: Z1 U& K: N - if ($tags) {, H) v. Z( O/ }3 T& l3 D
- echo 'Related Posts';8 ?' Q+ u& D* W' [9 B% t+ s8 N' c7 Q
- $first_tag = $tags[0]->term_id;* T" p$ g2 ^6 I+ c* s2 r* r0 Y
- $args=array(
8 }. G4 j# ?1 r/ @$ w' {! D - 'tag__in' => array($first_tag),: q# N f8 ?5 U: g
- 'post__not_in' => array($post->ID),
+ T+ H3 a1 M$ d- S - 'showposts'=>5,2 b& F4 N7 o! e( H8 I5 ?$ w
- 'caller_get_posts'=>1
/ `. C- O, A. k) T4 ? `# B& X* Z - );
1 Z5 f; W8 k7 k! D3 T - $my_query = new WP_Query($args);
- ?' S; A/ O P( u( B - if( $my_query->have_posts() ) {
# l6 w5 k1 ]& r: @6 Y3 q - while ($my_query->have_posts()) : $my_query->the_post(); ?>
! u1 p3 o6 q; q8 o H - <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>$ T% Z, R; k- n. U
- <?php* b! ?. Y: e, ~
- endwhile;* d& Q2 o# T( Q1 N/ t3 M9 i; |( g
- }
& W- j" \5 k* p$ d" f3 u: f0 Y - }8 Z/ v7 q |* K* A, L: W
- ?>
复制代码 根据当前文章的第一个tag,显示5篇related posts。 |
|