编辑“WordPress:Alphabetizing Posts”
该编辑可以被撤销。 请检查下面的对比以核实您想要撤销的内容,然后发布下面的更改以完成撤销。
最后版本 | 您的文本 | ||
第1行: | 第1行: | ||
__TOC__ | __TOC__ | ||
By default, WordPress organizes and displays posts in descending chronological order: newest first, oldest last. Sometimes, though, you might want to list posts in alphabetical order. Using different templates in WordPress, you may implement post listings in an alternative manner. | By default, WordPress organizes and displays posts in descending chronological order: newest first, oldest last. Sometimes, though, you might want to list posts in alphabetical order. Using different templates in WordPress, you may implement post listings in an alternative manner. | ||
==Category Template== | ==Category Template== | ||
For example, say you have a category named "Glossary" that serves as (obviously) a glossary, where each post is a definition of a specific term, and each term is used as the post title. You want one master list of all the terms, plus their definitions. Edit your theme's <tt>[[WordPress:Category_Templates|category.php]]</tt> file, and make the following changes, just before [[WordPress:The Loop]]: | For example, say you have a category named "Glossary" that serves as (obviously) a glossary, where each post is a definition of a specific term, and each term is used as the post title. You want one master list of all the terms, plus their definitions. Edit your theme's <tt>[[WordPress:Category_Templates|category.php]]</tt> file, and make the following changes, just before [[WordPress:The Loop]]: | ||
<pre> | <pre> | ||
第35行: | 第23行: | ||
if (have_posts()) : while (have_posts()) : the_post(); ?> | if (have_posts()) : while (have_posts()) : the_post(); ?> | ||
</pre> | </pre> | ||
===Specific Category Template=== | ===Specific Category Template=== | ||
If you want your "Glossary" category to have a very different style from the rest of your site, you could create a custom category template file just for it. First, find the category ID of your "Glossary" category. The category ID is listed in the left-most column of your [[WordPress:Administration_Panels#Manage_-_Change_your_content|Manage]] > [[WordPress:Administration_Panels#Categories|Categories]] administration panel. For this example, we'll assume that the "Glossary" category has a category ID of 13. | If you want your "Glossary" category to have a very different style from the rest of your site, you could create a custom category template file just for it. First, find the category ID of your "Glossary" category. The category ID is listed in the left-most column of your [[WordPress:Administration_Panels#Manage_-_Change_your_content|Manage]] > [[WordPress:Administration_Panels#Categories|Categories]] administration panel. For this example, we'll assume that the "Glossary" category has a category ID of 13. | ||
Copy your theme's <tt>index.php</tt> or <tt>category.php</tt> file (or create a brand new file, if necessary) named <strong><tt>category-13.php</tt></strong>, and insert your code as needed: | Copy your theme's <tt>index.php</tt> or <tt>category.php</tt> file (or create a brand new file, if necessary) named <strong><tt>category-13.php</tt></strong>, and insert your code as needed: | ||
<pre> | <pre> | ||
第91行: | 第44行: | ||
if (have_posts()) : while (have_posts()) : the_post(); ?> | if (have_posts()) : while (have_posts()) : the_post(); ?> | ||
</pre> | </pre> | ||
Using a separate category template file for your "Glossary" category means that you do not clutter up your main <tt>category.php</tt> file with a bunch of conditional template tags. | Using a separate category template file for your "Glossary" category means that you do not clutter up your main <tt>category.php</tt> file with a bunch of conditional template tags. | ||
==Index Templates== | ==Index Templates== | ||
Maybe you want to list <em>all</em> your posts alphabetically on the main page. Edit your theme's <tt>index.php</tt>: | Maybe you want to list <em>all</em> your posts alphabetically on the main page. Edit your theme's <tt>index.php</tt>: | ||
<pre> | <pre> | ||
第138行: | 第61行: | ||
<!-- commenting out as the parameters shown for wp_get archives are wrong | <!-- commenting out as the parameters shown for wp_get archives are wrong | ||
=Archives List= | =Archives List= | ||
To display a list of links to your posts, sorted in alphabetical order, use the following: | To display a list of links to your posts, sorted in alphabetical order, use the following: | ||
<pre> | <pre> | ||
第176行: | 第73行: | ||
==References== | ==References== | ||
* [[WordPress:Category Templates|Customizing Category Templates]] | * [[WordPress:Category Templates|Customizing Category Templates]] | ||
* [[WordPress:The Loop in Action]] | * [[WordPress:The Loop in Action]] | ||
* [http://wordpress.org/support/topic/22801#post-149393 WordPress Support Forum Thread on Sorting Posts and Categories Alphabeticlly] | * [http://wordpress.org/support/topic/22801#post-149393 WordPress Support Forum Thread on Sorting Posts and Categories Alphabeticlly] | ||