王桂明在修改Loper1.3主题时,发现相关文章是文字形式的,如下图:
没那么美观,修改为缩略图形式的,操作如下:
将loper的style.css中relate标签分隔栏替换成下面内容:
/*--Relate--*/ .relatebar{clear:both; margin:10px 0;}.relatebar .Related_Posts{margin-top:9px; margin-left:15px; width:700px}.relatebar .Related_Posts_tittle{margin-top:3px; line-height:17px; color:#515151 !important; font-size:12px !important; width:112px; overflow:hidden}.relatebar .Related_Posts li{float:left; margin:0 32px 0 0;display: block;}.relatebar .Related_Posts ul li img{width:90px; height:90px; background:#F4F4F4; border:1px solid #D8D8D8; padding:2px} |
接着在loper的single.php中的
<ul> <?php $post_tags = wp_get_post_tags($post->ID); if ($post_tags) { foreach ($post_tags as $tag) {$tag_list[] .= $tag->term_id;} $post_tag = $tag_list[ mt_rand(0, count($tag_list) - 1) ]; $args = array( 'tag__in' => array($post_tag), 'category__not_in' => array(NULL), 'post__not_in' => array($post->ID), 'showposts' => 6, 'caller_get_posts' => 1 ); query_posts($args); if (have_posts()) : while (have_posts()) : the_post(); update_post_caches($posts); ?> <li><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></li> <?php endwhile; else : ?> <li>暂无相关文章</li> <?php endif; wp_reset_query(); } ?> </ul> |
替换为:
<div class="clear"></div> <div class="Related_Posts"><ul><?php $post_num = 4;$exclude_id = $post->ID;$posttags = get_the_tags(); $i = 0;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),'ignore_sticky_posts' => 1,'orderby' => 'comment_date','posts_per_page' => $post_num);query_posts($args);while( have_posts() ) { the_post(); ?><li><a href="<?php the_permalink(); ?> " rel="nofollow"><?php post_thumbnail( 90,90 ); ?></a><div class="Related_Posts_tittle"><a class="Related_Posts_tittle" href="<?php the_permalink(); ?>" ><?php the_title(); ?></a></div></li><?php $exclude_id .= ',' . $post->ID; $i ++;} 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),'ignore_sticky_posts' => 1,'orderby' => 'comment_date','posts_per_page' => $post_num - $i);query_posts($args);while( have_posts() ) { the_post(); ?><li><a href="<?php the_permalink(); ?> " rel="nofollow"><?php post_thumbnail( 90,90 ); ?></a><div class="Related_Posts_tittle"><a class="Related_Posts_tittle" href="<?php the_permalink(); ?>" ><?php the_title(); ?></a></div></li><?php $i++;} wp_reset_query();}if ( $i == 0 ) echo '<li>没有相关文章!</li>';?></ul></div> <div class="clear"></div> |
在刷新一下看效果:
» 本文链接:
http://www.0523jz.com/69.html
» 订阅本站:
http://www.0523jz.com/feed
» 转载请注明来源:王桂明's Blog
» 《给loper1.3主题加上缩略图相关文章》