首先需要说明的一点是,如果你在网站页面中点击了分类页面,那么wordpress首先会自动寻找category-X.php文件,其中的X代表分类页面的ID,比如在飞鱼的声纳,category-44.php代表的就是有关时间管理的分类页面,要查看分类页面的ID号,你可以将鼠标放置于分类列表上,在浏览器的左下角就能看到类似于 http://startwmlife.com/?cat=44的链接,其中的数字44就是此分类页面的ID。如果在你的wordpress主题文件夹中不存在category-X.php文件,那么wordpress就会寻找category.php文件,如果category.php文件也不存在,它就会寻找archive.php文件,如果archive.php文件依然不存在,wordpress就会接下来寻找index.php文件,这个文件肯定是有的,要不然wordpress主题也就不能成为主题了。一般来说,设计者所设计的wordpress主题中,至少包括index.php文件和archive.php文件。
下面是一个category-x.php文件示例:
<?php get_header(); ?>
<div id="content">
<div id="contentleft">
<div class="postarea">
<?php include(TEMPLATEPATH."/breadcrumb.php");?>
<h1><?php single_cat_title(''); ?></h1>
<!-- 上面h1标签中的代码调用分类页面标题,比如"时间管理" -->
<img src="<?php bloginfo('template_url'); ?>/images/motorcycles.png" alt="<?php bloginfo('name'); ?>:
<?php single_cat_title('',); ?>" />
<!-- 上面img标签中的代码调用指定到分类页面的图片,比如指定给时间管理页面的一个钟表图片。这个图片要预先上传到主题文件夹内 -->
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h1><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h1>
<div class="date">
<div class="dateleft">
<p><span class="time"><?php the_time('F j, Y'); ?></span> by <?php the_author_posts_link(); ?>
<?php edit_post_link('(Edit)', '', ''); ?> <br /> Filed under <?php the_category(', ') ?></p>
</div>
<div class="dateright">
<p><span class="comment"><?php comments_popup_link('Leave a Comment', '1 Comment', '% Comments'); ?>
</span></p>
</div>
</div>
<?php the_content(__('Read more'));?><div style="clear:both;"></div>
<div class="postmeta2">
<p><span class="tags">Tags: <?php the_tags('') ?></span></p>
</div>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p><?php endif; ?>
<p><?php posts_nav_link(' — ', __('« Previous Page'), __('Next Page »')); ?></p>
</div>
</div>
<?php include(TEMPLATEPATH."/sidebar.php");?>
</div>
<!-- The main column ends -->
<?php get_footer(); ?>
这篇文章有23个评论. 留下评论