接着就是在需要添加该功能的地方加入代码片段,具体代码如下:
代码开始<ul><?php
$args=array(
'cat' => 1, // 分类ID
'posts_per_page' => 8, // 总共显示篇数
);
query_posts($args);
if(have_posts()) : $j=0; while (have_posts()) : $j++; the_post(); update_post_caches($posts);
?><?php if($j>2 //显示图片标题数量,剩余的只显示标题连接,参考 百知生活 可看到具体效果
) { ?>
<li><a title="<?php the_title(); ?>" href="<?php the_permalink(); ?>"><img width="240" height="240"src="<?php echo catch_first_image() ?>" alt="<?php the_title(); ?>"></a><a title="<?php the_title();?>"href="<?php the_permalink();?>"><?php the_title();?></a></li>
<?php } else { ?>
<li><a title="<?php the_title();?>"href="<?php the_permalink();?>"><?php the_title();?></a></li>
<?php } ?>
<?php endwhile; endif; wp_reset_query();?></ul>
代码结束
添加好以上步骤的代码后,就可以实现调用指定的分类实现显示不同样式了。
具体的div显示样式需要自己调整,比如分类宽度,样式图片的大小等。
联系客服