WordPress: Alphabetizing Posts:修订间差异

来自站长百科
跳转至: 导航、​ 搜索
(新页面: __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 o...)
 
无编辑摘要
 
第1行: 第1行:
__TOC__
__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.
默认情况下,WordPress是以相反的时间顺序组织并且显示文章的是:最新发表的文章最新显示,最早写的文章最后显示。但是,有时候,你可能想要按字母表顺序显示文章。使用WordPress中不同的模板,你可能使用另一种方式显示文章列表。


==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]]:
例如,假如你有一个类别,名称为"术语表"作为(明显地)术语表,每篇文章定义了某个术语,那个术语就作为文章的标题。你想要所有术语,以及这些术语的定义的一个列表。编辑你的主题<tt>[[WordPress:Category_Templates|category.php]]</tt>文件,并且更改,在[[WordPress:The Loop|The Loop]]之前:


<pre>
<pre>
第23行: 第35行:
if (have_posts()) : while (have_posts()) : the_post(); ?&gt;
if (have_posts()) : while (have_posts()) : the_post(); ?&gt;
</pre>
</pre>
<pre>
&lt;?php
get_header();
?&gt;
&lt;div id="content"&gt;
&lt;?php
// 我们添加这个,
// 按字母表顺序,在术语表中显示所有的文章
if (is_category('Glossary'))
{
    $posts = query_posts($query_string .
'&orderby=title&order=asc&posts_per_page=-1');
}
// 下面是 Loop!
if (have_posts()) : while (have_posts()) : the_post(); ?&gt;
</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]] &gt; [[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]] &gt; [[WordPress:Administration_Panels#Categories|Categories]] administration panel.  For this example, we'll assume that the "Glossary" category has a category ID of 13.
如果你希望"术语表"类别的样式与站点的其它部分的样式不同,你可以为术语表创建一个自定义类别模板文件。首先,找到你的"术语表"类别的ID。类别ID列在[[WordPress:Administration_Panels#Manage_-_Change_your_content|管理]] &gt; [[WordPress:Administration_Panels#Categories|类别]]管理面板最左边的栏中。在这个例子中,我们假定"术语表"类别的ID是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:
复制你的主题的<tt>index.php</tt> 或者 <tt>category.php</tt> 文件(或者如果必须的话,创建一个新文件)命名为<strong><tt>category-13.php</tt></strong>,如果需要的话,插入你的代码:


<pre>
<pre>
第44行: 第91行:
if (have_posts()) : while (have_posts()) : the_post(); ?&gt;
if (have_posts()) : while (have_posts()) : the_post(); ?&gt;
</pre>
</pre>
<pre>
&lt;?php
get_header();
?&gt;
&lt;div id="content"&gt;
&lt;?php
// 我们添加这个,
//以字母表顺序,在术语表中显示所有文章
$posts = query_posts($query_string .
'&orderby=title&order=asc&posts_per_page=-1');
// 下面是Loop!
if (have_posts()) : while (have_posts()) : the_post(); ?&gt;
</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.
为你的"术语表"类别使用单独的类别模板文件,意味着你不需要将主要的<tt>category.php</tt>文件和一些条件式标签混乱在一起。


==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>:
也许你想要在主页上按字母表顺序列表你的<em>所有的</em>文章。编辑你的主题的<tt>index.php</tt>:


<pre>
<pre>
第61行: 第138行:


<!--  commenting out as the parameters shown for wp_get archives are wrong  
<!--  commenting out as the parameters shown for wp_get archives are wrong  
<pre>
&lt;?php
// 我们列出这个
// 根据文章标题的字母表顺序,显示*所有的*文章
    $posts = query_posts($query_string . '&orderby=title&order=asc&posts_per_page=-1');
//下面是Loop!
if (have_posts()) : while (have_posts()) : the_post(); ?&gt;
</pre>
<!--  commenting out因为为 wp_get 归档显示的参数是错误的
=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>
&lt;?php
wp_get_archives('type=postbypost&sort=post_title&order=ASC');
?&gt;
</pre>
-->


<pre>
<pre>
第73行: 第176行:


==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]
* [[WordPress:Category Templates|自定义类别模板]]
* [[WordPress:The Loop in Action|运转的Loop]]
* [http://wordpress.org/support/topic/22801#post-149393 WordPress 支持论坛关于按字母表顺序给文章和类别分类的主题]

2008年7月28日 (一) 16:29的最新版本



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.

默认情况下,WordPress是以相反的时间顺序组织并且显示文章的是:最新发表的文章最新显示,最早写的文章最后显示。但是,有时候,你可能想要按字母表顺序显示文章。使用WordPress中不同的模板,你可能使用另一种方式显示文章列表。

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 category.php file, and make the following changes, just before WordPress:The Loop:

例如,假如你有一个类别,名称为"术语表"作为(明显地)术语表,每篇文章定义了某个术语,那个术语就作为文章的标题。你想要所有术语,以及这些术语的定义的一个列表。编辑你的主题category.php文件,并且更改,在The Loop之前:

<?php
get_header();
?>

<div id="content">

<?php
// we add this, to show all posts in our
// Glossary sorted alphabetically
if (is_category('Glossary')) 
{
     $posts = query_posts($query_string . 
'&orderby=title&order=asc&posts_per_page=-1');
} 
// here comes The Loop!
if (have_posts()) : while (have_posts()) : the_post(); ?>



<?php
get_header();
?>

<div id="content">

<?php
// 我们添加这个,
// 按字母表顺序,在术语表中显示所有的文章
if (is_category('Glossary')) 
{
     $posts = query_posts($query_string . 
'&orderby=title&order=asc&posts_per_page=-1');
} 
// 下面是 Loop!
if (have_posts()) : while (have_posts()) : the_post(); ?>



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 Manage > Categories administration panel. For this example, we'll assume that the "Glossary" category has a category ID of 13.

如果你希望"术语表"类别的样式与站点的其它部分的样式不同,你可以为术语表创建一个自定义类别模板文件。首先,找到你的"术语表"类别的ID。类别ID列在管理 > 类别管理面板最左边的栏中。在这个例子中,我们假定"术语表"类别的ID是13.

Copy your theme's index.php or category.php file (or create a brand new file, if necessary) named category-13.php, and insert your code as needed:

复制你的主题的index.php 或者 category.php 文件(或者如果必须的话,创建一个新文件)命名为category-13.php,如果需要的话,插入你的代码:


<?php
get_header();
?>

<div id="content">

<?php
// we add this, to show all posts in our 
// Glossary sorted alphabetically
$posts = query_posts($query_string . 
'&orderby=title&order=asc&posts_per_page=-1');
// here comes The Loop!
if (have_posts()) : while (have_posts()) : the_post(); ?>


<?php
get_header();
?>

<div id="content">

<?php
// 我们添加这个,
 //以字母表顺序,在术语表中显示所有文章
$posts = query_posts($query_string . 
'&orderby=title&order=asc&posts_per_page=-1');
// 下面是Loop!
if (have_posts()) : while (have_posts()) : the_post(); ?>




Using a separate category template file for your "Glossary" category means that you do not clutter up your main category.php file with a bunch of conditional template tags.

为你的"术语表"类别使用单独的类别模板文件,意味着你不需要将主要的category.php文件和一些条件式标签混乱在一起。

Index Templates[ ]

索引模板[ ]

Maybe you want to list all your posts alphabetically on the main page. Edit your theme's index.php:

也许你想要在主页上按字母表顺序列表你的所有的文章。编辑你的主题的index.php

<?php
// we add this, to show *all* posts sorted
// alphabetically by title
     $posts = query_posts($query_string . '&orderby=title&order=asc&posts_per_page=-1');
// here comes The Loop!
if (have_posts()) : while (have_posts()) : the_post(); ?>


<?php
wp_get_archives('type=postbypost&sort=post_title&order=ASC'); 
?>

-->

References[ ]

参考[ ]