WordPress: Pages:修订间差异

来自站长百科
跳转至: 导航、​ 搜索
无编辑摘要
无编辑摘要
第35行: 第35行:
* '''Pages''' 可以被组织安排在页面或者[[Wordpress:#Organizing_your_Pages|'''子页面''']]中。
* '''Pages''' 可以被组织安排在页面或者[[Wordpress:#Organizing_your_Pages|'''子页面''']]中。
* '''Pages''' 可以使用不同的 '''[[Wordpress:#Page Templates|页面模板]]''' ,它可以包括 [[Wordpress:Stepping Into Templates|模板文件]], [[Wordpress:Template Tags|模板标签]] 和其他的PHP代码。
* '''Pages''' 可以使用不同的 '''[[Wordpress:#Page Templates|页面模板]]''' ,它可以包括 [[Wordpress:Stepping Into Templates|模板文件]], [[Wordpress:Template Tags|模板标签]] 和其他的PHP代码。
===What Pages are Not===
* '''Pages''' are not Posts, nor are they excerpted from larger works of fiction.  They do not cycle through your blog's main page. ('''Note:''' You can include Posts in Pages by using the [http://aralbalkan.com/wordpress/ Inline Posts Plugin].)
* '''Pages''' cannot  be associated with Categories and cannot be assigned Tags. The organizational structure for Pages comes only from their hierarchical interrelationships, and not from Tags or Categories.
* '''Pages''' are not files.  They are stored in your database just like Posts are.
* Although you can put Template Tags and PHP code into a Page Template, you cannot put these into the content of a Page and expect them to run. ('''Note''': You can achieve this by using a PHP evaluating Plugin such as [http://wordpress.org/extend/plugins/exec-php/ Exec-PHP] or [http://dev.wp-plugins.org/wiki/RunPHP RunPHP].) <!-- The page has been deleted, commenting out link. See also the list of [[Wordpress:Plugins/Posts Formatting|Posts Formatting Plugins]].) -->


=== Pages 不是什么===
=== Pages 不是什么===


* '''Pages''' 不是 Posts, 也不是从其他大的作品中的摘录。同时,它不在你的博客的主页上循环。('''注:''' 通过使用[http://aralbalkan.com/wordpress/ Inline Posts 插件],在Pages 中可以包含Posts 。)
* '''Pages''' 不是 Posts, 也不是从其他大的作品中的摘录。同时,它不在你的博客的主页上循环。('''注:''' 通过使用[http://aralbalkan.com/wordpress/ Inline Posts 插件],在Pages 中可以包含Posts 。)
 
* '''Pages''' 不能和类别联系到一起也不能指派标签。该组织结构的页面只能来自他们的层次相互关系,而不是从标签或分类
==Creating Pages==
* '''Pages''' 不是文件。它们象文章一样存储在你的数据库中。
 
* 尽管你能够把模板标签和PHP代码放入一个Page模板,但是你不能把他们放入一个Page内容中并且期望它们能运行。
To create a new Page, log in to your WordPress installation with sufficient admin privileges to create new articles. In the [[Wordpress:Administration Panels|Administration Panel]], choose the [[Wordpress:Administration_Panels#Write_-_Make_some_content|Write]] Panel and then choose the [[Wordpress:Write Page SubPanel|Write Page]] SubPanel to access the page where you can create your new Page.
 
<!-- is the .htaccess information here valid for wp 2.x.x pages ? isn't it only related to 1.- versions ?? I didn't want to make a change here until i'm sure.
7-26-06 -- chradil
 
:Yes, this is true. I removed the paragraph. -- [[Wordpress:User:Mastermind|Mastermind]] 09:13, 26 Aug 2007 (UTC)
-->


==创建 Pages==
==创建 Pages==
第66行: 第52行:
:Yes, this is true. I removed the paragraph. -- [[Wordpress:User:Mastermind|Mastermind]] 09:13, 26 Aug 2007 (UTC)
:Yes, this is true. I removed the paragraph. -- [[Wordpress:User:Mastermind|Mastermind]] 09:13, 26 Aug 2007 (UTC)
-->
-->
==Listing Your Pages on Your Site==
WordPress is able to ''automatically'' generate a list of Pages on your site, for example within the sidebar, using a [[Wordpress:Template Tags|Template Tag]] called <tt>wp_list_pages()</tt>.  See the [[Wordpress:Template Tags/wp_list_pages|wp_list_pages]] page for information on how to
*sort the list of Pages (to fully customize the order in which the Pages are listed, you might find the "Page Order" field on the Write > Write Page administration panel <!-- [[Wordpress:USER:MDAWaffe/Write Page SubPanel]] -->useful),
*[[Wordpress:Template Tags/wp_list_pages#Exclude Pages from List|exclude]] (or 'hide') a Page from the list,
*control which Pages are displayed (i.e., all Pages or just certain SubPages), and
*control how deep into your Page hierarchy the list goes.
Naturally, you can also link to Pages manually with an HTML link.  For example, if you want your Copyright Page listed in your footer, that link might read as below: <br />
'''If you ''do not'' have [[Wordpress:Using Permalinks|Permalinks]] set up'''
<a title="Copyright information" href="wordpress/?page_id=14">Copyright 1996-2006</a>
'''If you ''do'' have [[Wordpress:Using Permalinks|Permalinks]] set up'''
<a title="Copyright information" href="wordpress/copyright/">Copyright 1996-2006</a>
'''Note''': Your .htaccess file ''must'' be writeable for Page Permalinks to work, otherwise you must update your .htaccess file every time you create a Page.


==将Pages 列在主页上==
==将Pages 列在主页上==
第101行: 第70行:


'''注意''':要想让友好连接页面正常工作,.htaccess文件''必须''是可写状态,否则你必须每次创建新的Page的时候更新一次你的.htaccess文件。
'''注意''':要想让友好连接页面正常工作,.htaccess文件''必须''是可写状态,否则你必须每次创建新的Page的时候更新一次你的.htaccess文件。
==Organizing Your Pages==
Just as you can have Subcategories within your Categories, you can also have '''SubPages''' within your Pages, creating a hierarchy of pages.


==Pages的组织==
==Pages的组织==

2008年4月8日 (二) 17:14的版本

介绍

Pages, 或者叫 WordPress Pages 就象 Posts一样,除了功能比Posts多的多以外,它们不属于普通的博客时间列表范围。你可以使用Pages来组织和管理任意数量的内容。在WordPress 1.5.中,Pages加入了一些新的功能。

但是Pages在WordPress是如何运作的呢?本文的目标就是尝试解释Page是什么,不是什么,描述Page可做些什么,并举例说明。


Terms Used in this Article

为了明确起见,通过本文:

  • "page", 使用小写的"p", 可以描述 任何 HTML 网站上的内容
  • "Page", 使用大写的 "P", 特指 "WordPress Page", 本wiki页面详细的WordPress功能。 当使用期间不明确的时候使用"Page"的粗体.

有关更多的Page术语,参见[[Wordpress:#A Note on Nomenclature|有关术语的记录]].

Page是什么?

Posts是时间导向的对象。你在某一时间写下它们,时间确定了它们的上下文。

Pages,从另一方面说,更多的是用来表述有关你自己的或者你的网站,不知原因的,无时间的一直可用的信息。举例来说,你写了一篇Post描述了某个早晨你做了什么或者想了什么("Breakfast was good"),但是在Page上你可能会写一些与时间无关的内容("This site is about breakfast").

当然了,这是“你的”WordPress;你可以用它的功能来实现任何你想做的事。Pages可以用来显示任何你想现在在你的博客“外部”的信息。试验,创造,还有,永远充满乐趣。

网站上的Pages可能包括的内容有:版权、法定信息、再版许可、联系信息、关于本人、关于网站、无障碍声明或者其他东西。

通常说来,Pages和Posts是非常相似的,它们都有标题和内容,可以使用网站的现有模板来保持整个网站的风格的一致性。尽管如此,Pages仍然有几点主要的特性明显区别于Posts

Pages简介

Pages 是什么

  • Pages的内容不如Posts的时间性强。
  • Pages 可以被组织安排在页面或者[[Wordpress:#Organizing_your_Pages|子页面]]中。
  • Pages 可以使用不同的 [[Wordpress:#Page Templates|页面模板]] ,它可以包括 模板文件, 模板标签 和其他的PHP代码。

Pages 不是什么

  • Pages 不是 Posts, 也不是从其他大的作品中的摘录。同时,它不在你的博客的主页上循环。(注: 通过使用Inline Posts 插件,在Pages 中可以包含Posts 。)
  • Pages 不能和类别联系到一起也不能指派标签。该组织结构的页面只能来自他们的层次相互关系,而不是从标签或分类
  • Pages 不是文件。它们象文章一样存储在你的数据库中。
  • 尽管你能够把模板标签和PHP代码放入一个Page模板,但是你不能把他们放入一个Page内容中并且期望它们能运行。

创建 Pages

要创建一个新的Page,先登陆有足够的管理权限的WordPress帐户来创建新的条目。在管理员面板中,选择书写Page子面板,就可以创建新的Page了。


将Pages 列在主页上

WordPress会自动的在主页上生成一个Pages列表,例如在边栏,使用一个叫做wp_list_pages()模板标签,参见wp_list_pages页面,是有关:

  • 如何分类Pages列表, (想完全自定义Pages列表的顺序,请在Write > Write Page administration panel useful中找到"Page Order"这项)
  • 如何在一个列表中排除 (or '隐藏') Page。
  • 如何控制哪个Pages 将被显示(i.e., 所有的 Pages 或者只是特定的子页面)
  • 如何控制你的Page层次中,列表处在第几层

当然,你也可以使用一个HTML连接手动连接到Pages。例如,如果你想让你的版权页面显示在页脚,你可以这样写:
If you do not have Permalinks set up

<a title="Copyright information" href="wordpress/?page_id=14">Copyright 1996-2006</a>

If you do have Permalinks set up

<a title="Copyright information" href="wordpress/copyright/">Copyright 1996-2006</a>

注意:要想让友好连接页面正常工作,.htaccess文件必须是可写状态,否则你必须每次创建新的Page的时候更新一次你的.htaccess文件。

Pages的组织

就象你的分类中有子类一样,在你的Pages中同样也有子页面,以创建更多层的页面。

For example, suppose you are creating a WordPress site for a travel agent and would like to create an individual Page for each continent and country to which the agency can make travel arrangements. You would begin by creating a Page called "Africa" on which you could describe general information about travel to Africa. Then you would create a series of Pages which would be SubPages to "Africa" and might include "Lesotho", "Cameroon", "Togo", and "Swaziland". Another individual Page is made for "South America" and would feature SubPages of "Brazil", "Argentina", and "Chile". Your site would then list:

  • Africa
    • Cameroon
    • Lesotho
    • Swaziland
    • Togo
  • South America
    • Argentina
    • Brazil
    • Chile

例如,假设你正在为一个旅游机构建立一个WordPress网站,并且想为每个大陆和国家建立一个单独的Page,这样这个旅游机构可以作出旅游安排。可以建立一个叫做" Africa "的Page,在这页面上描述到非洲旅游的大致信息。然后你再建立一系列的Pages作为" Africa "的子页面,可以包括"Lesotho", "Cameroon", "Togo", and "Swaziland"等等,另外一个单独的Page叫做" South America ",子页面可以是"Brazil", "Argentina", and "Chile",那么你的网站排列如下:

  • Africa
    • Cameroon
    • Lesotho
    • Swaziland
    • Togo
  • South America
    • Argentina
    • Brazil
    • Chile

To begin the process, go to Administration > Write > Write Page panel, in the upper right corner of the panel and click the "Page Parent" drop-down menu. The drop-down menu contains a list of all the Pages already created for your site. To turn your current Page into a SubPage, or "Child" of the "Parent" Page, select the appropriate Page from the drop-down menu. If you specify a Parent other than "Main Page (no parent)" from the list, the Page you are now editing will be made a Child of that selected Page. When your Pages are [[Wordpress:#Listing Your Pages on Your Site|listed]], the Child Page will be nested under the Parent Page. The Permalinks of your Pages will also reflect this Page hierarchy.

开始的时候,先查看管理 > 书写 > 书写Page 面板,在面板的右上方点击"Page Parent"下拉菜单,其中包含了你的网站上所有已经创建的Page,要想从现Page转向一个子页,或者是"父"页面的"子"页面,选择下拉菜单中的适当的页面就可以了。如果你从列表中指定一个不同于"主页面 (无父页面)"的父页面,那么你现在正在编辑的页面将成为这个选中的页面的子页。当页面[[Wordpress:#Listing Your Pages on Your Site|列出]]时,子页将被嵌套在父页中。页面中的 友好连接也会反映出了这个页面层次。

In the above example, the Permalink for the Cameroon Page would be:

http://example.com/africa/cameroon/

上述例子中,Cameroon 页面的友好连接是: http://example.com/africa/cameroon/

Page Templates

Individual Pages can be set to use a specific custom Page Template (a PHP template file, e.g., snarfer.php) you create within your Theme (see [[Wordpress:#Creating your own Page Templates|Creating your own Page Templates]] below on how to create a custom template). This new Page Template will then override the default page.php Page Template included with your Theme. See [[Wordpress:#What Template is used to Display a Particular Page?|What Template is used to Display a Particular Page?]] below, to find out exactly which Template will be used, but read the following first, so you understand the answer :)

WordPress can be configured to use different Page Templates for different Pages. Toward the bottom of the Write > Write Page administration panel (or on the sidebar, depending on which version of WordPress you are using) is a drop-down labeled "Page Template". From there you can select which Template will be used when displaying this particular Page.

NOTE: In order to access the Page Template selector, there must be at least one custom Page Template available in the active theme (see [[Wordpress:#Creating your own Page Templates|Creating your own Page Templates]] below to learn how to create one).

页面模板

单独的页面可以设置成使用一个你自己建立在你的主题中的详细的自定义页面模板 (一个 PHP 模板文件, 比如 snarfer.php) (参见下文有关如何建立自定义模板 [[Wordpress:#Creating your own Page Templates|建立自己的页面模板]] )。新的页面模板将覆盖主题中的默认page.php页面模板,参见下面的 [[Wordpress:#What Template is used to Display a Particular Page?|用什么模板来显示特定的页面?]],准确找出哪种模板将被用到,请先阅读下文,答案就会揭晓:)

WordPress可以设置成使用不同的页面使用不同的模板。在书写 > 页面书写管理面板的底部(或者是在边栏,取决于你使用了何种版本的WordPress ),是一个下拉菜单"页面模板",显示特定的页面时从那里你可以选择使用哪种模板。

注意:为了进入模板选择器,在现有主题中至少必须有一个可用的自定义页面模板。(参见下面的[[Wordpress:#Creating your own Page Templates|建立自己的页面模板]]来学习如何建立页面模板。)

Default Theme Page Templates

The Default theme contains three Page Templates for your use:

  • page.php - Default Page Template: displays Page content
  • archives.php - ignores Page content and instead displays a list of Archives by Month and Archives by Subject (by Category)
  • links.php - ignores Page content and instead displays your links using get_links_list

默认主题页面模板

默认主题有三个页面模板可用:

  • page.php -默认主题模板: 显示页面内容
  • archives.php - 忽略页面内容,根据日期和标题(分类)显示文档。
  • links.php - 忽略页面内容,使用 得到连接列表显示连接。

What Template is used to Display a Particular Page?

WordPress will look for several template files in your active Theme. The first one it finds will be used to display any given Page. WordPress will look for files in the following order:

  1. The Page's selected "Page Template"
  2. page.php
  3. index.php

页面用什么模板显示?

WordPress会在现用的主题中寻找几个模板文件。第一个找到的用来显示给定的页面,WordPress会按照下列顺序寻找文件:

  1. 该页面选中的 "页面模板"
  2. page.php
  3. index.php


Creating Your Own Page Templates

The files defining each Page Template are found in your Themes directory. To create a new Template for a Page you must create a file. Let's call our first Page Template for our Page snarfer.php. At the top of the snarfer.php file, put the following:

<?php
/*
Template Name: Snarfer
*/
?>

创建自己的页面模板

定义每个页面模板的文件可以在主题目录中找到。想要建立一个新的模板,你必须建立一个新文件。让我们把第一个页面模板命名为snarfer.php。在snarfer.php文件的顶部,输入:

<?php
/*
Template Name: Snarfer
*/
?>

The above code defines this snarfer.php file as the "Snarfer" Template. Naturally, "Snarfer" may be replaced with most any text to change the name of the Page Template. This Template Name will appear in the Theme Editor as the link to edit this file.

上边的代码定义了snarfer.php文件为"Snarfer"模板。当然了,"Snarfer"可以被替换为任何其他的文字来改变页面模板的名字。这个模板的名字将会出现在主题编辑器中,作为编辑这个模板文件的连接。

The file may be named almost anything with a .php extension (see reserved Theme filenames for filenames you should not use; these are special file names WordPress reserves for specific purposes).

这个文件可以被命名为几乎任何以.php为扩展名。(参见 主题文件名保留字,可以找到你不可以用来作为文件名的一些字段;这些是WordPress为特殊目的而保留的特殊文件名)。

What follows the above five lines of code is up to you. The rest of the code you write will control how Pages that use the Snarfer Page Template will display. See Wordpress:Template Tags for a description of the various WordPress Template functions you can use for this purpose. You may find it more convenient to copy some other Template (perhaps page.php or index.php) to snarfer.php and then add the above five lines of code to the beginning of the file. That way, you will only have to alter the HTML and PHP code, instead of creating it all from scratch. Examples are shown [[Wordpress:#Examples|below]]. Once you have created the Page Template and placed it in your Theme's directory, it will be available as a choice when you create or edit a Page. (Note: when creating or editing a Page, the Page Template option does not appear unless there is at least one template defined in the above manner.)

上边五行代码后边如何编写,取决于你。剩余的代码将控制使用Snarfer页面模板的页面如何显示。参见 模板标签可以找到可用的各种实现此目标的WordPress模板功能的描述。你会发现复制其他模板(可能是 page.php or index.php</tt文件>)的内容到snarfer.php,然后把这五行代码加入代码的开头部分更加方便。那样的话,你只需要更改HTML和PHP代码,而不用重头开始再创建新的文件。示例详见[[Wordpress:#Examples|下部]]。一旦创建了页面模板,并放入了主题文件夹,创建或者边界页面的时候就可以使用它了。(注意: 创建或者编辑页面时,页面模板操作选项并不显示,除非有至少一种模板使用上述方法定义后才可以使用。)

==Examples of Pages and Templates==

The following is a list of instructional examples. Feel free to make additions.

==页面和模板示例==

The following is a list of instructional examples. Feel free to make additions

以下是示例列表,随时可添加

Archives with Content

A Page Template that shows the Page's content at the top, and then displays a list of archive months and categories below it. This is designed to work with WordPress's Default theme (aka Kubrick), but will probably work with many other themes with a little modification.

Save this to arc-cont.php:

<?php
/*
Template Name: Archives with Content
*/
?>

<?php get_header(); ?>

<div id="content" class="widecolumn">

 <?php if (have_posts()) : while (have_posts()) : the_post();?>
 <div class="post">
  <h2 id="post-<?php the_ID(); ?>"><?php the_title();?></h2>
  <div class="entrytext">
   <?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
  </div>
 </div>
 <?php endwhile; endif; ?>
 <?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>

</div>
<div id="main">

<?php include (TEMPLATEPATH . '/searchform.php'); ?>

<h2>Archives by Month:</h2>
  <ul>
    <?php wp_get_archives('type=monthly'); ?>
  </ul>

<h2>Archives by Subject:</h2>
  <ul>
     <?php wp_list_cats(); ?>
  </ul>

</div>
<?php get_footer(); ?>

有目录的文档

显示页面目录的页面模板在最上边,然后是一个按月或者分类的文档列表。这样设计对WordPress的默认主题(aka Kubrick)起作用,可能对其他很多主题有少许修改。

保存如下代码到 arc-cont.php:

<?php
/*
Template Name: Archives with Content
*/
?>

<?php get_header(); ?>

<div id="content" class="widecolumn">

 <?php if (have_posts()) : while (have_posts()) : the_post();?>
 <div class="post">
  <h2 id="post-<?php the_ID(); ?>"><?php the_title();?></h2>
  <div class="entrytext">
   <?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
  </div>
 </div>
 <?php endwhile; endif; ?>
 <?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>

</div>
<div id="main">

<?php include (TEMPLATEPATH . '/searchform.php'); ?>

<h2>Archives by Month:</h2>
  <ul>
    <?php wp_get_archives('type=monthly'); ?>
  </ul>

<h2>Archives by Subject:</h2>
  <ul>
     <?php wp_list_cats(); ?>
  </ul>

</div>
<?php get_footer(); ?>


WordPress as a CMS

With the new Pages feature in 1.5+, it's easy to use WordPress for basic content management.

作为CMS使用WordPress

有了1.5及以后版本的新页面功能,将更加容易的使用WordPress进行基本内容管理。

Using a Page as the Front Page (version 2.1+ only)

WordPress 2.1 introduced the Option to conveniently set any Page as your Front Page. Go to Options > Reading in the Wordpress Admin interface. Under the Front Page Category, you can choose to set any (published) Page or Posts Page as the Front Page. The default setting shows your blog with the latest blog posts.

使用页面作为首页 (仅限版本2.1及以上)

WordPress 2.1加入了方便的设置任何页面作为首页的操作。在Wordpress管理界面中找到Options > Reading。在首页分类下,你可以选择设置任何(发布过的)页面或者帖子作为首页。默认的设置是显示最新的博客帖子。

Note: In 2.1, the conditional is_home() function no longer returns true for the Front Page set in Admin. In order to emulate the pre-2.1 function of returning true for the "front" home page, use the is_frontpage plugin or use is_page(home) where the slug of your desired front page is "home".

注意:在2.1版本中,有条件的is_home()功能在管理面板中首页设置中不再返回真值。为了与2.1以前的版本的"front"即主页的返回真的功能保持一致,使用首页插件或者使用is_page(home),这样你所想要的首页就会成为"主页"了。

The following paragraphs explain how to duplicate this functionality for versions prior to v2.1.

下面的章节将阐述如何与2.1以前的版本的功能性保持一致

Using a Page as the Front Page with WordPress Versions Prior to v2.1

Using the Static Front Page Plugin, it is possible to set any Page as the "front page" of your site. The Plugin modifies the home page query and sticks the Page with a Page slug of "home" to the front page.

WordPress 2.1之前的版本中使用一个页面作为首页

使用Using the 静态首页插件,可以设置任何页面为"首页"。插件修改主页查询,然后粘贴这个带有简短说明的"主页"页面到首页。

When the Page is being displayed as the homepage, if a Page Template with the filename home.php exists for your active Theme, the Plugin will override the Page's set Page Template and use home.php instead. The Page's set Page Template will still apply if the Page is visited like a standard Page (e.g., http://example.com/home/)

当该页面作为主页显示的时候,如果一个文件名为home.php的页面模板存在于现用的主题中,插件就会覆盖页面设置页面模板,然后使用home.php替代它。如果该页面象标准页面访问时,页面设置页面模板仍然适用。(如, http://example.com/home/)

As an alternative to the Plugin, WordPress will recognize a "home.php" document in your template directory and use it rather than index.php to theme your front page. However, if your home page isn't your blog, be advised that the home.php template will always apply to the blog page whether you like it or not. Using the query_posts() template tag, you can call on any page before you invoke Wordpress:The Loop. For instance:

<?php 
     query_posts('pagename=home'); 
?>

Will call up only the post with the pagename "home." See query_posts() for more examples of the template tag in action.

The home.php file is not needed in versions 2.1+. Use the setting in the control panel to set your static home page.

作为插件的替代,WordPress会识别你的模板目录中的"home.php"文件,并使用它而不使用index.php来作为首页的主题。尽管如此,如果你的主页不是你的博客,不论你喜欢与否,home.php模板都将应用于你的博客。使用 帖子查询() 模板标签,你可以在调用循环之前访问任何页面。如:

<?php 
     query_posts('pagename=home'); 
?>

将调用含有页面名字"home"的帖。参见 贴查询()查看更多有关模板标签的示例。

home.php文件并不是2.1以上版本所必须的。使用控制面板可以设置你的静态主页。

Including a Page

You might also want to include Pages in various places on your site. That way, you can have an easy way to edit elements of your website. There is a Plugin called Include Page that makes doing this easy. Improved Include Page is a more updated version of the Plugin.

包含一个页面

你也许也想在你的网站上的多个地方包含多个页面,那样,你就可以更方便的编辑你的网站了。有一种叫做Include Page的插件,可以让这变的简单。Include Page改进版可以找到这个插件更新的版本

Making Your Blog Appear in a Non-Root Folder

Suppose you have WordPress running at http://example.com/. Also, suppose that you want your blog to be located at http://example.com/blog/ and that you want other pages to be available at http://example.com/page1/.

让你的博客出现在非根文件夹

假如你有一个WordPress在http://example.com/运行,再假设你想要你的博客定位在http://example.com/blog/,然后希望别的页面可以在http://example.com/page1 浏览。

The first thing you will want to do is to create a homepage. You can do this by creating home.php in your theme directory. Next, create a blog template. The easiest way to do this is to create a file named blog.php with the following contents in your theme directory:


<?php
/*
Template Name: Blog
*/

// Which page of the blog are we on?
$paged = get_query_var('paged');
query_posts('cat=-0&paged='.$paged);

// make posts print only the first part with a link to rest of the post.
global $more;
$more = 0;

//load index to show blog
load_template(TEMPLATEPATH . '/index.php');
?>

首先你要做的是建立一个主页。你可以通过在主题目录中建立一个home.php来实现。下一步,建立一个博客模板。最简单的方法就是在主题目录下建立一个名字为blog.php的文件,包含以下内容

<?php
/*
Template Name: Blog
*/

// Which page of the blog are we on?
$paged = get_query_var('paged');
query_posts('cat=-0&paged='.$paged);

// make posts print only the first part with a link to rest of the post.
global $more;
$more = 0;

//load index to show blog
load_template(TEMPLATEPATH . '/index.php');
?>

Log in to WordPress and create a page named "Blog" with Template "blog". You're done. The one last thing you will want to do is to update your permalinks structure to begin with "/blog/", i.e., "/blog/%year%/%monthnum%/%postname%/". Now you have a WordPress-managed CMS with a unique front page and logically-structured blog content.

登陆WordPress使用模板"blog"建立一个名为"Blog"的页面,这样就完成了。最后要做的就是更新友情连接的结构,以"/blog/"开头,如"/blog/%year%/%monthnum%/%postname%/"。现在你就有了一个带有独一无二的首页和逻辑结构的博客内容的WordPress管理的CMS了。

If you're using the <!-- more --> quicktag to place things below the fold in your posts, you'll want to include the global variable $more and set it to zero (as shown in the code above). Otherwise, the entire post will print out on your blog's main page.

如果你正在使用<!-- more --> 快捷标签,来把东西放进你的文章,你会想包含全局变量$more并且把它设置为零。(如上代码所示)。否则,整个的文章将会显示在你的博客主页上。

As noted above, the home.php file is not needed in versions 2.1+. If both the blog.php and home.php files are deployed in 2.1+ they will conflict and cause the blog.php templated page to appear blank.

如上所述,home.php文件在版本2.1以上时不是必须的。如果blog.php和 home.php同时在2.1以上版本使用就会产生冲突,造成blog.php模板页面显示为空白。

A Note on Nomenclature

A page can be static or dynamic. Static pages are those which have been created once and do not have to be regenerated every time a person visits it. In contrast, dynamic pages do need to be regenerated every time they are viewed; code for what to generate has been specified by the author, but not the actual page itself. These use extensive PHP code which is evaluated each time the page is visited, and the content is thus generated on the fly, upon each new visit.

关于术语

一个页面可以是静态的 或者动态的。静态页面是那些一次性创建出来,并且不用每个人访问后都重新生成的。相对的,动态页面每次访问后需要重新生成;生成什么样的页面的代码由作者声明,但不是实际上的页面本身。这些使用每访问一次就重新评估的扩展PHP代码,内容根据新的访问随时生成。

Almost everything in WordPress is generated dynamically, including Pages. Everything you and others write in WordPress (Posts, Pages, Comments, Blogrolls, Categories, etc.) is stored in your MySQL database. When your site is accessed, that database information is then used by your WordPress Templates from your current Theme to generate the web page being requested. Thus, WordPress information is dynamic, including the information contained in your Pages.

WordPress中几乎所有的东西都是动态生成的,包括Pages。你或者其他人写的任何东西 (Posts, Pages, Comments, Blogrolls, Categories, etc.)都存储在你的MySQL数据库中。当有人进入你的网页时,数据库信息就会被WordPress 模板主题中调用,来生成要求的页面。这样,WordPress信息是动态的,包括了你的Pages中的信息。


An example of a static page might be an HTML document (without any PHP code) you've written as an addition to your dynamically generated WordPress pages, perhaps an "About Me" page. The problem with purely static pages is that they are difficult to maintain. Changes you make to your WordPress settings, Themes and Templates will not be propagated to pages coded only in HTML. The Page feature of WordPress was developed, in part, to alleviate this problem. By using Pages, users no longer have to update their static pages every time they change the style of their site. Instead, if written properly, their dynamic Pages will update themselves along with the rest of your blog.

静态页面的例子就是你写用来添加到动态生成WordPress 页面中的 HTML文件(不包括任何PHP代码) 比方说"About Me" 页面.纯静态页面的问题在于它们很难维护.你做出的任何有关WordPress设置, 主题模板的任何改动,不能只在HTML页面中传递. WordPress 的Page功能被扩展了,一定程度上的解决了这个问题.通过使用Pages,使用者不再每次作出更改后必须更新他们的静态页面了.取而代之的,如果适当的写他们的动态页面将连同他们的博客的其他部分一起更新。

Despite the dynamic nature of Pages, many people refer to them as being static. In the context of web publishing, static and dynamic mean what has been described above. More generally, however, static can mean "characterized by a lack of change". It is easy to see how this definition influenced the word's use in describing types of web pages. It is also to easy to see why people think of Pages as being static; Posts come and go, but Pages are here to stay since Pages are typically used to display information about your site which is constant (e.g., information about yourself, description of your site).

不论动态页面的本质如何,很多人仍然把它们当作静态页面。在页面内容发布来说,静态和动态意味着上边描述了什么。更广泛的看,静态意味着"缺乏变化的特点",很容易看出这个定义如何影响描述网页形式时词的应用。同样也很容易看出为什么人们把Pages认为是静态的,帖子的随时更新,但是从有关你的网站显示的信息被显示后,Pages却一直存在。(如:有关你自己的信息,描述你的网站的信息)

In other words, a Page contains static information but is generated dynamically. Thus, either "static" or "dynamic" may be validly used to describe the nature of the WordPress Page feature. However, in order to avoid confusion, and because Pages themselves are dynamic while it is only their contents which are in some way static, this document does not refer to Pages as being static.

换句话说,Page包含了静态信息,但却是动态生成。这样,不管是静态或者动态,都可以用来描述WordPress Page的本质。尽管如此,为了避免混淆,再加上当它们的内容有些情况下是静态的时候,Pages本身却是是动态的,本文不认为Pages是静态的。