category.php的制作
- <?php
- /* 功能:
- * 判断是否为分类目录别名,如果不是,则使用category-default.php 分类目录模板
- * 如果是,则使用对应的分类目录模板
- */
- if ( is_category('pic') ) { //当访问 http://www.cnsecer.com/pic这个分类时,使用category-pic.php这个模板
- include(TEMPLATEPATH . '/cate-thumb.php');
- }
- // elseif 结束 //如果访问其他分类,则使用category-default.php'这个模板
- else {
- include(TEMPLATEPATH . '/cate-default.php');
- }
- ?>
然后就是他们两个都包含了右边的那个sidebar,sidebar的这个我们先不讲,等category的讲完了再讲sidebar。
首先来看下第一种category的主要代码
他大致包含三个部分:左边缩略图,文章标题和文章内容。
缩略图代码如下
- <div class="col-md-3 hidden-xs">
- <div class="thumb">
- <a href="#"><img src="<?php post_thumbnail_src();?>" alt="缩略图" class="img-rounded"></a>
- </div>
- </div>
- //col-md-3 hidden-xs 都是bootstrap的属性 ,详细说明请查看:<a href="http://v3.bootcss.com/css/#responsive-utilities">http://v3.bootcss.com/css/#responsive-utilities</a>
- //<?php post_thumbnail_src();?> 显示缩略图
显示文章标题和文章内容:
- <!--content begin-->
- <div class="col-md-9">
- <div class="cate-article-content">
- <div class="hcontent">
- <a href="<?php the_permalink() ?>" target="_blank"><?php echo mb_strimwidth(get_the_title(), 0, 43,"...") ?></a>
- </div>
- <div class="fcontent">
- <p><?php echo mb_strimwidth(strip_tags($post->post_content), 0,550,"..."); ?></p>
- </div>
- </div>
- </div>
- <!--content end-->