wordpress相关文章列表
WordPress相关文章列表,先获取标签相关文章,如标签下相关文章不能达到设置数量,获取同类目文章
<?php
$i = 0;
$post_num = 8;//设置文章显示数量
$exclude_id = $post->ID;//排查当前文章
$posttags = get_the_tags();//获取标签
if ( $posttags ) {
$tags = ''; foreach ( $posttags as $tag ) $tags .= $tag->term_id . ',';
$args = array(
'post_status' => 'publish',
'tag__in' => explode(',', $tags),
'post__not_in' => explode(',', $exclude_id),
'caller_get_posts' => 1,
'orderby' => 'comment_date',
'posts_per_page' => $post_num
);
query_posts($args);
while( have_posts() ) { the_post(); $i++; $exclude_id .= ',' . $post->ID;
?>
<div class="about_good fl <?php if($i%2==0){echo 'li-2';} if($i%3==0){echo ' li-3';} if($i%4==0){echo ' li-4';}?>">
<a rel="bookmark" target="_blank" href="<?php the_permalink(); ?>"><?php post_thumbnail(); ?></a>
<div class="title"><a rel="bookmark" title="详细阅读 <?php the_title(); ?>" target="_blank" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
</div>
<?php } wp_reset_query();}
if ( $i < $post_num ) {
$cats = ''; foreach ( get_the_category() as $cat ) $cats .= $cat->cat_ID . ',';
$args = array(
'category__in' => explode(',', $cats),
'post__not_in' => explode(',', $exclude_id),//排除标签已显示的文章
'caller_get_posts' => 1,
'orderby' => 'comment_date',
'posts_per_page' => $post_num - $i
);
query_posts($args);
while( have_posts() ) { the_post();
?>
<div class="about_good fl <?php if($i%2==0){echo 'li-2';} if($i%3==0){echo ' li-3';} if($i%4==0){echo ' li-4';}?>">
<a rel="bookmark" target="_blank" href="<?php the_permalink(); ?>"><?php post_thumbnail(); ?></a>
<div class="title"><a rel="bookmark" title="详细阅读 <?php the_title(); ?>" target="_blank" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
</div>
<?php } wp_reset_query(); }?>
以上带图片,需要在function中设置略缩图