这里值得注意的是Wordpress的模板层次结构。(http://codex.wordpress.org/Template_Hierarchy)
这些模板基本上覆盖了所有Wordpress页面所需的99%。如果您在这样一个模板的领域内工作,就不需要生成自己的查询,Wordpress已经这样做了,您所要做的就是生成一个循环来显示结果。
这是一个相当标准的存档。我用来在博客上显示归档文件的php。
<?php
get_header();
$post = $posts[0]; // Hack. Set $post so that the_date() works.
/* If this is a category archive */ if (is_category()) {
$title =__(single_cat_title(\'\', false));
/* If this is a tag archive */ } elseif( is_tag() ) {
$title =__(\'Tag: \', "krautgaming")." ".single_tag_title(\'\', false);
/* If this is a daily archive */ } elseif (is_day()) {
$title =__(\'Archive for \', "krautgaming").get_the_time(__(\'F jS, Y\', "krautgaming")).__(\' | Daily archive page\', "krautgaming");
/* If this is a monthly archive */ } elseif (is_month()) {
$title =__(\'Archive for \', "krautgaming").get_the_time(__(\'F, Y\', "krautgaming")).__(\' | Monthly archive page\', "krautgaming");
/* If this is a yearly archive */ } elseif (is_year()) {
$title =__(\'Archive for \', "krautgaming").get_the_time(__(\'Y\', "krautgaming")).__(\' | Yearly archive page\', "krautgaming");
/* If this is an author archive */ } elseif (is_author()) {
$title =__(\'Author Archive\', "krautgaming");
/* If this is a paged archive */ } elseif (isset($_GET[\'paged\']) && !empty($_GET[\'paged\'])) {
$title =__(\'Blog Archives\', "krautgaming");
/* If this is a channel archive */ } elseif (is_tax(\'channel\')) {
$title =__(\'Videos by\', "krautgaming")." ".single_tag_title(\'\', false);
/* If this is a video archive */ } elseif (is_post_type_archive(\'video\')) {
$title =__(\'Recent Videos\', "krautgaming");
} else {
$title =__("Recent Posts", "krautgaming");
}
?>
<div class="sub_header">
<div class="container">
<div class="row">
<div class="span6">
<h1><?php echo $title; ?></h1>
</div>
</div>
</div>
</div>
<div class="center-container container">
<?php
if( have_posts() ): while( have_posts() ): the_post();
?>
<!-- Display posts here -->
<?php
endwhile; endif;
?>
</div>
<?php
get_footer();
?>