WordPress: Creating an Archive Index:修订间差异

来自站长百科
跳转至: 导航、​ 搜索
(新页面: == Introduction == So you want a single page with links to all your archived entries, arranged <em>just so</em> to form the main gateway into your blog's past. With the WordPress 1.5 the...)
 
无编辑摘要
第1行: 第1行:
== Introduction ==
== Introduction ==
== 介绍说明==


So you want a single page with links to all your archived entries, arranged <em>just so</em> to form the main gateway into your blog's past. With the WordPress 1.5 theme system, you can create template files to customize this archive gateway for each theme you use.
So you want a single page with links to all your archived entries, arranged <em>just so</em> to form the main gateway into your blog's past. With the WordPress 1.5 theme system, you can create template files to customize this archive gateway for each theme you use.
你想要一个单独的网页,这个网页上拥有所有的链接连接到你的归档内容中,<em>这样</em>安排来形成一个主要的路径,查看博客上过去写的文章。拥有了WordPress1.5主题系统,你可以创建模板文件来为你使用的每个主题自定义这个进入归档的路径。


Or, maybe you're just wondering how to use the <tt>archives.php</tt> template file that's included with the WordPress Default Theme.
Or, maybe you're just wondering how to use the <tt>archives.php</tt> template file that's included with the WordPress Default Theme.
或者,也许你只是不知道哦啊怎样使用WordPress默认主题中所包含的<tt>archives.php</tt>模板文件。


This article describes both those things. The method outlined here can also be used to make other specialized pages that are integrated with the WordPress theme system: a links page, site index, or anything else your heart desires.
This article describes both those things. The method outlined here can also be used to make other specialized pages that are integrated with the WordPress theme system: a links page, site index, or anything else your heart desires.
本篇文章描述了上述的两种情况。这里所列的方法能够用来产生其它的与WordPress主题系统结合的特别的网页:一个链接网页,站点索引,或者任何你想要的内容。


== Creating the Archive Index Template and Page ==
== Creating the Archive Index Template and Page ==
== 创建归档索引模板和网页 ==


To set up a separate archive index in a way that plays with the Version 1.5 theme system, you'll need to create it as a [[WordPress:Pages | Page]], and assign it a special template.
To set up a separate archive index in a way that plays with the Version 1.5 theme system, you'll need to create it as a [[WordPress:Pages | Page]], and assign it a special template.
要创建一个单独的归档索引,使其在某种程度上能够与WordPress1.5主题系统一起运行,你需要将这个索引以网页的形式创建,并且这个网页提交给一个特别的模板。


=== The Template (archives.php) ===
=== The Template (archives.php) ===
=== 模板 (archives.php) ===


Start off with a simple template called <tt>archives.php</tt>, stored in your theme's directory. The WordPress Default Theme includes such a template, and it makes a good starting point.
Start off with a simple template called <tt>archives.php</tt>, stored in your theme's directory. The WordPress Default Theme includes such a template, and it makes a good starting point.
以一个简单的,称为<tt>archives.php</tt>的模板开始,这个模板储存在你的主题的目录上。WordPress默认主题包括这样一个模板,而且这个模板成为了一个很好的开始。


Technically, the template can be called almost anything (see [[WordPress:Theme Development#Theme Templates|these two lists]] for names you should ''not'' use; these are special file names WordPress reserves for specific purposes). However, using a standard name for your template will make it easier to change your blog's theme or distribute your theme and template to the WordPress community. It's also possible to display a large archive index using one of the all-purpose templates (like index.php or category.php) and the [[WordPress:Conditional_Tags|is_page]] function, but again, taking advantage of the theme system's modularity makes it easier for others (and for you!) to edit your template later.
Technically, the template can be called almost anything (see [[WordPress:Theme Development#Theme Templates|these two lists]] for names you should ''not'' use; these are special file names WordPress reserves for specific purposes). However, using a standard name for your template will make it easier to change your blog's theme or distribute your theme and template to the WordPress community. It's also possible to display a large archive index using one of the all-purpose templates (like index.php or category.php) and the [[WordPress:Conditional_Tags|is_page]] function, but again, taking advantage of the theme system's modularity makes it easier for others (and for you!) to edit your template later.
一般来说,模板可以任意命名(请看看[[WordPress:Theme Development#Theme Templates|这两个列表]]上你''不''应该使用的命名;WordPress保存了一些特别的文件名用于特别的目的)。但是,使用一个标准的模板名,能够更容易地更改你的博客名,更容易将你的主题和模板分发到WordPress团体。使用一个多用途的模板(像index.php或者category.php)和[[WordPress:Conditional_Tags|是_网页]]函数能够显示一个大的归档索引,但是利用主题系统的模块性,使得他人(和你自己!)能够更容易编辑你的模板。


For more information on creating templates, see [[WordPress:Template_Tags|Template Tags]], particularly [[WordPress:Template_Tags/wp_get_archives | wp_get_archives]].
For more information on creating templates, see [[WordPress:Template_Tags|Template Tags]], particularly [[WordPress:Template_Tags/wp_get_archives | wp_get_archives]].
关于创建模板的更多的信息,请看看[[WordPress:Template_Tags|模板标签]], 特别是[[WordPress:Template_Tags/wp_get_archives | wp_得到_归档]]。


=== The Archives Page ===
=== The Archives Page ===
=== 归档网页 ===


==== for WP 1.5 ====
==== for WP 1.5 ====
==== WP 1.5 ====


Upload the archives.php in your theme directory (<tt>wp-content/themes/themename/</tt>). Then from the Admin Panel, [[WordPress:Pages#Creating_Pages|'''Write > Write Page''']], and choose '''Add a New Page''':
Upload the archives.php in your theme directory (<tt>wp-content/themes/themename/</tt>). Then from the Admin Panel, [[WordPress:Pages#Creating_Pages|'''Write > Write Page''']], and choose '''Add a New Page''':
将archive.php上传到你的主题目录(<tt>wp-content/themes/themename/</tt>)上。然后在管理面板上,[[WordPress:Pages#Creating_Pages|'''写 > 编写网页''']], 选择 '''添加一个新网页''':


# Give your new archives Page a suitable title like ''Archive Index''. Leave the Page content blank.
# Give your new archives Page a suitable title like ''Archive Index''. Leave the Page content blank.
#赋予你的新的归档网页一个合适的标题,像''归档索引''。将网页内容保留空白。
# Under '''Custom Fields''', select '''_wp_page_template''' from the dropdown. Leave the Key field blank, and enter '''archives.php''' into the '''Value''' field.
# Under '''Custom Fields''', select '''_wp_page_template''' from the dropdown. Leave the Key field blank, and enter '''archives.php''' into the '''Value''' field.
#在'''自定义区'''下面,从下拉列表上选择'''_wp_网页_模板'''。将关键词区保持空白,并且在'''参数值'''区输入'''archives.php'''。
# Click '''Add Custom Field'''.
# Click '''Add Custom Field'''.
#点击'''添加自定义范围'''。
# Voila! Your archive index can be accessed at <tt><nowiki>http://example.com/index.php?pagename=archive-index</nowiki></tt>.
# Voila! Your archive index can be accessed at <tt><nowiki>http://example.com/index.php?pagename=archive-index</nowiki></tt>.
#完成了!可以在<tt><nowiki>http://example.com/index.php?pagename=archive-index</nowiki></tt>访问你的归档索引。


==== for WP 1.5+ ====
==== for WP 1.5+ ====
==== for WP 1.5+ ====


Upload the archives.php in your theme directory  
Upload the archives.php in your theme directory  
(<tt>wp-content/themes/themename/</tt>). Then from the Admin Panel, [[WordPress:Pages#Creating_Pages|'''Write > Write Page''']]
(<tt>wp-content/themes/themename/</tt>). Then from the Admin Panel, [[WordPress:Pages#Creating_Pages|'''Write > Write Page''']]
将archives.php上传到你的主题目录上(<tt>wp-content/themes/themename/</tt>)。然后从管理面板,[[WordPress:Pages#Creating_Pages|'''写 > 编写网页''']]


# Give your new archives Page a suitable title like ''Archive Index''. Leave the Page content blank.
# Give your new archives Page a suitable title like ''Archive Index''. Leave the Page content blank.
#赋予你的新的归档网页一个合适的标题,像''Archive Index''。将网页内容保留为空白。


In the sidebar open the //Page templates// box, and select the //Archives// template. After saving it you will see a new item in your pages list, click on it, and enjoy!
In the sidebar open the //Page templates// box, and select the //Archives// template. After saving it you will see a new item in your pages list, click on it, and enjoy!
在工具条上,打开//网页模板// 框,然后选择//归档// 模板。保存后,你在你的网页列表上会看到一个新的文章,点击,阅读!


== Customizing Your Archives ==
== Customizing Your Archives ==
== 自定义你的归档 ==


There are a variety of techniques to customize your Archive Index page. Some involve incorporation of plugins or PHP code to create customized lists of archived posts, and others provide more interesting ways of displaying your archives.
There are a variety of techniques to customize your Archive Index page. Some involve incorporation of plugins or PHP code to create customized lists of archived posts, and others provide more interesting ways of displaying your archives.
有许多中方法可以用来自定义你的归档索引网页。有的方法包括包含插件或者PHP编码来创建归档文章的自定义列表,其它的方法提供了更加有趣的方式来显示你的归档。


=== List Archives By Year ===
=== List Archives By Year ===
=== 根据年份来列出归档文章===


You can set your archives up to be displayed by the year, such as:
You can set your archives up to be displayed by the year, such as:
你可以将你的文档来按年份显示,像:
<div style="border:1px solid blue; width:40%; font-weight:110%; margin: 20px; padding:20px">
<span style="font-weight:bold;font-size:120%">Archives</span>
<ul style="color:blue">
<li><u>2007</u></li>
<li><u>2006</u></li>
<li><u>2005</u></li>
<li><u>2004</u></li>
</ul>
</div>


<div style="border:1px solid blue; width:40%; font-weight:110%; margin: 20px; padding:20px">
<div style="border:1px solid blue; width:40%; font-weight:110%; margin: 20px; padding:20px">
第58行: 第124行:


To list your archives by year instead of by month, use the following code, in which a query to the database is made to collect and sort the posts by year, then display them as links with the [[WordPress:Template_Tags/get_year_link|get_year_link()]] template tag:
To list your archives by year instead of by month, use the following code, in which a query to the database is made to collect and sort the posts by year, then display them as links with the [[WordPress:Template_Tags/get_year_link|get_year_link()]] template tag:
将你的归档按照年份而不是按照月份,使用以下的编码,数据库中的一个查询,能够收集文章并且将文章按年份来分类,然后,将文章显示,拥有链接[[WordPress:Template_Tags/get_year_link|得到_年份_链接()]] 模板标签:
<pre><ul><li><h2>Archives</h2>
<ul>
<?php
$years = $wpdb->get_col("SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_date DESC");
foreach($years as $year) :
?>
<li><a href="<?php echo get_year_link($year); ?> "><?php echo $year; ?></a></li>
<?php endforeach; ?>
</ul>
</li></ul></pre>


<pre><ul><li><h2>Archives</h2>
<pre><ul><li><h2>Archives</h2>
第71行: 第152行:


For versions of WordPress before 2.1, use this for your '''$years''' query:
For versions of WordPress before 2.1, use this for your '''$years''' query:
对于2.1版本之前的WordPress版本,使用这个来作为你的'''$年份'''查询:
<pre>$years = $wpdb->get_col("SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date DESC");</pre>


<pre>$years = $wpdb->get_col("SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date DESC");</pre>
<pre>$years = $wpdb->get_col("SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date DESC");</pre>


== Setting Up Redirects ==
== Setting Up Redirects ==
==设置 Redirects ==


If you're using [[WordPress:Using_Permalinks|Permalinks]], WordPress will generate a new set of [[WordPress:Pages#Creating_Pages|rewrite rules for your new Page]]. You may need to update your <tt>.htaccess</tt> file by hand, if WordPress is unable to do so automatically. See [[WordPress:Using_Permalinks|Using Permalinks]] for more information.
If you're using [[WordPress:Using_Permalinks|Permalinks]], WordPress will generate a new set of [[WordPress:Pages#Creating_Pages|rewrite rules for your new Page]]. You may need to update your <tt>.htaccess</tt> file by hand, if WordPress is unable to do so automatically. See [[WordPress:Using_Permalinks|Using Permalinks]] for more information.
如果你使用[[WordPress:Using_Permalinks|Permalinks]],WordPress会产生一组新的[[WordPress:Pages#Creating_Pages|你的新网页的重写规则]]。如果WordPress不能够自动地更新<tt>.htaccess</tt>文件,你可能要动手更新一下。更多的信息请看看[[WordPress:Using_Permalinks|使用 Permalinks]]。


These automatic rules are based on your Page title or "slug": If your Page is named Archive Index, you'll be able to see it at <tt><nowiki>http://example.net/your-wordpress-dir/archive-index/</nowiki></tt>.
These automatic rules are based on your Page title or "slug": If your Page is named Archive Index, you'll be able to see it at <tt><nowiki>http://example.net/your-wordpress-dir/archive-index/</nowiki></tt>.
这些自动的规则是以你的网页标题或者"slug"为基础的:如果你的网页命名为归档索引,你就能够在<tt><nowiki>http://example.net/your-wordpress-dir/archive-index/</nowiki></tt>看到你的网页。


=== Problems with Auto-generated .htaccess Files ===
=== Problems with Auto-generated .htaccess Files ===
=== 自动产生的 .htaccess 文件的问题 ===


If your archive index Page has a slug that's the same as part of your permalink structure - e.g., your Page is named Archives, and your permalinks are set up as <tt>/archives/%post-id%/</tt> or <tt>/archives/%year%/%monthnum%/%day%/%postname%/</tt> - WordPress will create conflicting rewrite rules. This can cause your monthly/category archives to be displayed using your archive index template.
If your archive index Page has a slug that's the same as part of your permalink structure - e.g., your Page is named Archives, and your permalinks are set up as <tt>/archives/%post-id%/</tt> or <tt>/archives/%year%/%monthnum%/%day%/%postname%/</tt> - WordPress will create conflicting rewrite rules. This can cause your monthly/category archives to be displayed using your archive index template.
如果你的归档索引网页有一个slug,这个slug与你的部分的permalink结构是相同的-例如,你的网页命名为归档,而且你的permalinks设置为<tt>/archives/%post-id%/</tt> 或者<tt>/archives/%year%/%monthnum%/%day%/%postname%/</tt> -WordPress会产生矛盾的重写规则。这个会导致你的按月/按类别的归档,使用你的归档索引模板显示。


There are two ways to avoid this problem:
There are two ways to avoid this problem:
下面是两种方法来避免这个问题:
# Use a different name for your archive index Page
# Use a different name for your archive index Page
#为你的归档索引网页使用不同的名称
# Don't allow WordPress to automatically manage your .htaccess file.
# Don't allow WordPress to automatically manage your .htaccess file.
#不要允许WordPress来自动地管理你的.htaccess文件。


== Further Reading ==
== Further Reading ==
== 深入阅读==


=== Useful Plugins ===
=== Useful Plugins ===
=== 有用的插件 ===


* [http://blindmuse.com/blog/2004/03/31/group-archives-by-year/ Group Archives By Year]
* [http://blindmuse.com/blog/2004/03/31/group-archives-by-year/ Group Archives By Year]
第96行: 第206行:
* [http://www.davidsaccess.com/?p=124 DC's Nicer Archives] - Create a list of archives that can be expanded from a bulleted list to a series of excerpts.
* [http://www.davidsaccess.com/?p=124 DC's Nicer Archives] - Create a list of archives that can be expanded from a bulleted list to a series of excerpts.
* [[WordPress:http://www.wordpress.org/extend/plugins|WordPress Plugins]] - for more possibilites.
* [[WordPress:http://www.wordpress.org/extend/plugins|WordPress Plugins]] - for more possibilites.
* [http://blindmuse.com/blog/2004/03/31/group-archives-by-year/ 根据年份来归档]
* [http://www.engadgeted.net/archives/2005/02/10/wordpress-heat-map-plugin/ WordPress Heat Map] – 根据存档中还有多少文章,用不同的大小和颜色来显示你的归档链接。
* [http://www.davidsaccess.com/?p=124 DC的更好的存档] – 创建存档的列表,这些列表可以从一个bulleted列表扩展为一系列摘录。
* [[WordPress:http://www.wordpress.org/extend/plugins|WordPress 插件]] - for more possibilites.


=== WordPress Support Forum Threads ===
=== WordPress Support Forum Threads ===
=== WordPress支持论坛主题===


* [http://wordpress.org/support/topic.php?id=18934 How to Use Archives.php of Ryan's Kubric Theme]
* [http://wordpress.org/support/topic.php?id=18934 How to Use Archives.php of Ryan's Kubric Theme]
* [http://wordpress.org/support/topic.php?id=24290 Year Archive Pulling Up Archives.php Page]
* [http://wordpress.org/support/topic.php?id=24290 Year Archive Pulling Up Archives.php Page]
* [http://wordpress.org/support/topic.php?id=18934 怎样使用 Ryan's Kubric 主题的Archives.php]
* [http://wordpress.org/support/topic.php?id=24290 年份归档 阻止 Archives.php 网页]


=== Interesting Examples of Archive Indexes ===
=== Interesting Examples of Archive Indexes ===
=== 关于存档索引的有趣的例子 ===


* [http://www.hitormiss.org/archives/ Hit or Miss] - Flickr-style weighted categories and keywords.
* [http://www.hitormiss.org/archives/ Hit or Miss] - Flickr-style weighted categories and keywords.
* [http://www.engadgeted.net/archives/ Engadgeted] - The Heat Map plugin in action.
* [http://www.engadgeted.net/archives/ Engadgeted] - The Heat Map plugin in action.
* [http://www.hitormiss.org/archives/ Hit or Miss] - Flickr-style 有利的类别和关键词
* [http://www.engadgeted.net/archives/ Engadgeted] – 运行的 Heat Map 插件。

2008年6月19日 (四) 11:38的版本

Introduction

介绍说明

So you want a single page with links to all your archived entries, arranged just so to form the main gateway into your blog's past. With the WordPress 1.5 theme system, you can create template files to customize this archive gateway for each theme you use.

你想要一个单独的网页,这个网页上拥有所有的链接连接到你的归档内容中,这样安排来形成一个主要的路径,查看博客上过去写的文章。拥有了WordPress1.5主题系统,你可以创建模板文件来为你使用的每个主题自定义这个进入归档的路径。

Or, maybe you're just wondering how to use the archives.php template file that's included with the WordPress Default Theme.

或者,也许你只是不知道哦啊怎样使用WordPress默认主题中所包含的archives.php模板文件。

This article describes both those things. The method outlined here can also be used to make other specialized pages that are integrated with the WordPress theme system: a links page, site index, or anything else your heart desires.

本篇文章描述了上述的两种情况。这里所列的方法能够用来产生其它的与WordPress主题系统结合的特别的网页:一个链接网页,站点索引,或者任何你想要的内容。

Creating the Archive Index Template and Page

创建归档索引模板和网页

To set up a separate archive index in a way that plays with the Version 1.5 theme system, you'll need to create it as a Page, and assign it a special template.

要创建一个单独的归档索引,使其在某种程度上能够与WordPress1.5主题系统一起运行,你需要将这个索引以网页的形式创建,并且这个网页提交给一个特别的模板。

The Template (archives.php)

模板 (archives.php)

Start off with a simple template called archives.php, stored in your theme's directory. The WordPress Default Theme includes such a template, and it makes a good starting point.

以一个简单的,称为archives.php的模板开始,这个模板储存在你的主题的目录上。WordPress默认主题包括这样一个模板,而且这个模板成为了一个很好的开始。

Technically, the template can be called almost anything (see these two lists for names you should not use; these are special file names WordPress reserves for specific purposes). However, using a standard name for your template will make it easier to change your blog's theme or distribute your theme and template to the WordPress community. It's also possible to display a large archive index using one of the all-purpose templates (like index.php or category.php) and the is_page function, but again, taking advantage of the theme system's modularity makes it easier for others (and for you!) to edit your template later.

一般来说,模板可以任意命名(请看看这两个列表上你应该使用的命名;WordPress保存了一些特别的文件名用于特别的目的)。但是,使用一个标准的模板名,能够更容易地更改你的博客名,更容易将你的主题和模板分发到WordPress团体。使用一个多用途的模板(像index.php或者category.php)和是_网页函数能够显示一个大的归档索引,但是利用主题系统的模块性,使得他人(和你自己!)能够更容易编辑你的模板。

For more information on creating templates, see Template Tags, particularly wp_get_archives.

关于创建模板的更多的信息,请看看模板标签, 特别是 wp_得到_归档

The Archives Page

归档网页

for WP 1.5

WP 1.5

Upload the archives.php in your theme directory (wp-content/themes/themename/). Then from the Admin Panel, Write > Write Page, and choose Add a New Page:

将archive.php上传到你的主题目录(wp-content/themes/themename/)上。然后在管理面板上,写 > 编写网页, 选择 添加一个新网页:

  1. Give your new archives Page a suitable title like Archive Index. Leave the Page content blank.
  1. 赋予你的新的归档网页一个合适的标题,像归档索引。将网页内容保留空白。
  1. Under Custom Fields, select _wp_page_template from the dropdown. Leave the Key field blank, and enter archives.php into the Value field.
  1. 自定义区下面,从下拉列表上选择_wp_网页_模板。将关键词区保持空白,并且在参数值区输入archives.php
  1. Click Add Custom Field.
  1. 点击添加自定义范围
  1. Voila! Your archive index can be accessed at http://example.com/index.php?pagename=archive-index.
  1. 完成了!可以在http://example.com/index.php?pagename=archive-index访问你的归档索引。

for WP 1.5+

for WP 1.5+

Upload the archives.php in your theme directory (wp-content/themes/themename/). Then from the Admin Panel, Write > Write Page

将archives.php上传到你的主题目录上(wp-content/themes/themename/)。然后从管理面板,写 > 编写网页

  1. Give your new archives Page a suitable title like Archive Index. Leave the Page content blank.
  1. 赋予你的新的归档网页一个合适的标题,像Archive Index。将网页内容保留为空白。

In the sidebar open the //Page templates// box, and select the //Archives// template. After saving it you will see a new item in your pages list, click on it, and enjoy!

在工具条上,打开//网页模板// 框,然后选择//归档// 模板。保存后,你在你的网页列表上会看到一个新的文章,点击,阅读!

Customizing Your Archives

自定义你的归档

There are a variety of techniques to customize your Archive Index page. Some involve incorporation of plugins or PHP code to create customized lists of archived posts, and others provide more interesting ways of displaying your archives.

有许多中方法可以用来自定义你的归档索引网页。有的方法包括包含插件或者PHP编码来创建归档文章的自定义列表,其它的方法提供了更加有趣的方式来显示你的归档。

List Archives By Year

根据年份来列出归档文章

You can set your archives up to be displayed by the year, such as:

你可以将你的文档来按年份显示,像:

Archives

  • 2007
  • 2006
  • 2005
  • 2004


Archives

  • 2007
  • 2006
  • 2005
  • 2004

To list your archives by year instead of by month, use the following code, in which a query to the database is made to collect and sort the posts by year, then display them as links with the get_year_link() template tag:

将你的归档按照年份而不是按照月份,使用以下的编码,数据库中的一个查询,能够收集文章并且将文章按年份来分类,然后,将文章显示,拥有链接得到_年份_链接() 模板标签:

<ul><li><h2>Archives</h2>
<ul>
<?php
$years = $wpdb->get_col("SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_date DESC");
foreach($years as $year) : 
?>
<li><a href="<?php echo get_year_link($year); ?> "><?php echo $year; ?></a></li>
<?php endforeach; ?>
</ul>
</li></ul>


<ul><li><h2>Archives</h2>
<ul>
<?php
$years = $wpdb->get_col("SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_date DESC");
foreach($years as $year) : 
?>
<li><a href="<?php echo get_year_link($year); ?> "><?php echo $year; ?></a></li>
<?php endforeach; ?>
</ul>
</li></ul>

For versions of WordPress before 2.1, use this for your $years query:

对于2.1版本之前的WordPress版本,使用这个来作为你的$年份查询:

$years = $wpdb->get_col("SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date DESC");


$years = $wpdb->get_col("SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY post_date DESC");

Setting Up Redirects

设置 Redirects

If you're using Permalinks, WordPress will generate a new set of rewrite rules for your new Page. You may need to update your .htaccess file by hand, if WordPress is unable to do so automatically. See Using Permalinks for more information.

如果你使用Permalinks,WordPress会产生一组新的你的新网页的重写规则。如果WordPress不能够自动地更新.htaccess文件,你可能要动手更新一下。更多的信息请看看使用 Permalinks

These automatic rules are based on your Page title or "slug": If your Page is named Archive Index, you'll be able to see it at http://example.net/your-wordpress-dir/archive-index/.

这些自动的规则是以你的网页标题或者"slug"为基础的:如果你的网页命名为归档索引,你就能够在http://example.net/your-wordpress-dir/archive-index/看到你的网页。

Problems with Auto-generated .htaccess Files

自动产生的 .htaccess 文件的问题

If your archive index Page has a slug that's the same as part of your permalink structure - e.g., your Page is named Archives, and your permalinks are set up as /archives/%post-id%/ or /archives/%year%/%monthnum%/%day%/%postname%/ - WordPress will create conflicting rewrite rules. This can cause your monthly/category archives to be displayed using your archive index template.

如果你的归档索引网页有一个slug,这个slug与你的部分的permalink结构是相同的-例如,你的网页命名为归档,而且你的permalinks设置为/archives/%post-id%/ 或者/archives/%year%/%monthnum%/%day%/%postname%/ -WordPress会产生矛盾的重写规则。这个会导致你的按月/按类别的归档,使用你的归档索引模板显示。

There are two ways to avoid this problem:

下面是两种方法来避免这个问题:

  1. Use a different name for your archive index Page
  2. 为你的归档索引网页使用不同的名称
  1. Don't allow WordPress to automatically manage your .htaccess file.
  1. 不要允许WordPress来自动地管理你的.htaccess文件。

Further Reading

深入阅读

Useful Plugins

有用的插件



WordPress Support Forum Threads

WordPress支持论坛主题


Interesting Examples of Archive Indexes

关于存档索引的有趣的例子