|
发表于 2013-1-29 21:28:30
|
显示全部楼层
- <?php; z+ c0 t5 o1 a: Q3 ]
- //for use in the loop, list 5 post titles related to first tag on current post9 m, R; f" N3 Q) x
- $tags = wp_get_post_tags($post->ID);
$ D9 w4 A; Q2 J - if ($tags) {
' r/ n9 p X3 ?* D) m* _, ]' D; N" ~ - echo 'Related Posts';9 ^. c) v0 K8 y" v6 {3 @1 \- }
- $first_tag = $tags[0]->term_id;
* o5 e1 ~; {+ S- X1 S - $args=array(
" c1 R& @/ v7 b x/ m' p, ]; Q - 'tag__in' => array($first_tag),2 x3 R# H6 U5 W" K6 S
- 'post__not_in' => array($post->ID),5 T O- }; ^8 P' u! `
- 'showposts'=>5,# M3 K+ {( e! ]% |! a) Z
- 'caller_get_posts'=>1
5 C% @, ~1 Y7 @3 p8 j - );3 F! e) f2 t4 z# A3 d# F' k3 K
- $my_query = new WP_Query($args);
" O% Z" |( \* y7 W5 C - if( $my_query->have_posts() ) {* s! d: Z* W! c1 c- v. O! N' r
- while ($my_query->have_posts()) : $my_query->the_post(); ?>
I2 [/ C4 J; O8 f: E - <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>8 j2 e# C- H$ b
- <?php
6 w8 b! E& J" M9 v - endwhile;; H' w- Y+ ^4 d
- }
* R9 x( R5 W% I5 N - }
2 {1 H- S& A* F: p: [9 H# P. e - ?>
复制代码 根据当前文章的第一个tag,显示5篇related posts。 |
|