|
|
发表于 2013-1-29 21:28:30
|
显示全部楼层
- <?php
$ D. `+ s) J5 C1 A1 m6 r - //for use in the loop, list 5 post titles related to first tag on current post
; _# z7 s1 K! a( w6 A. v - $tags = wp_get_post_tags($post->ID);
5 S9 M- e: {4 |: i3 e. I/ Q - if ($tags) {3 ?9 |, M: r7 @% }/ E
- echo 'Related Posts';3 @* A2 w% ]) L7 R# Q: I# @1 l6 G9 p- J
- $first_tag = $tags[0]->term_id;
( n, ~3 j' T+ f1 e* y" h - $args=array(7 B* ]9 w( _! ^% L
- 'tag__in' => array($first_tag),; t8 S. n2 S, x& K+ n
- 'post__not_in' => array($post->ID),, L# {7 L6 C6 ]: P2 e( G* t5 r' h
- 'showposts'=>5,
+ R8 M% n. Y% N% ]5 W, ~ - 'caller_get_posts'=>10 ~3 j# X; e; L; M( c
- );0 v0 r o4 y2 Q+ U
- $my_query = new WP_Query($args);
2 I j8 z/ s+ _1 Y( o: a1 o - if( $my_query->have_posts() ) {. L6 i- \5 V* t5 E7 P, l7 w
- while ($my_query->have_posts()) : $my_query->the_post(); ?>
$ f6 P% A/ E4 @ { - <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>6 z3 a' D s( `! H5 J
- <?php. P, r! {+ J% U" Q7 z B P
- endwhile;; D% M0 m- D2 T
- }5 k6 i3 ~+ a7 _, V
- }
P: b' g+ f' H* R! h - ?>
复制代码 根据当前文章的第一个tag,显示5篇related posts。 |
|