|
|
发表于 2013-1-29 21:28:30
|
显示全部楼层
- <?php
" A/ F1 O0 H* q# e3 C) c3 X - //for use in the loop, list 5 post titles related to first tag on current post' k3 q# O' t! [* [4 a
- $tags = wp_get_post_tags($post->ID);# @2 n% b; s6 N5 h8 \6 y) ?6 `
- if ($tags) {
& Y0 B& w t: g4 F - echo 'Related Posts';% W- l; O. ?/ a# N& `
- $first_tag = $tags[0]->term_id;
$ T# D# F4 I4 t) L5 Z& o - $args=array(
( V- e% \# t' h - 'tag__in' => array($first_tag),9 [+ d T4 I: J2 N3 g
- 'post__not_in' => array($post->ID),
4 }, B2 P! f0 |" r- h4 { - 'showposts'=>5,
2 r* [: t2 D! A: v - 'caller_get_posts'=>1+ N' ]0 D& m2 S9 T9 F# y
- );
; t, H+ s' @# S4 o - $my_query = new WP_Query($args);! J. B0 G- A, c7 e6 a+ H- y
- if( $my_query->have_posts() ) {; X I* P4 B6 `) u+ a
- while ($my_query->have_posts()) : $my_query->the_post(); ?>
/ X0 k7 Z5 P; e+ C$ T8 `5 t" T - <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
/ X9 b1 p( n5 R# w" l( J - <?php5 T2 X% w9 {; q/ n* S
- endwhile;
( `0 {' U3 z% ^, ~7 q - }* k. H5 P% i9 w9 F3 ~
- }$ a1 @ `9 C! `; k5 M6 L7 q
- ?>
复制代码 根据当前文章的第一个tag,显示5篇related posts。 |
|