• 赤色のリンクは、まだ日本語Codexに存在しないページ・画像です。英語版と併せてご覧ください。(詳細

このWikiはいつでも誰でも編集できます

固定ページ

提供: WordPress Codex 日本語版
2006年7月7日 (金) 03:12時点におけるNao (トーク)による版

(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先: 案内検索

はじめに

ページ」または「WordPressページ」は投稿(ブログの記事)と似ていますが、さらにフレキシブルな使い方ができ、ブログの時系列順の外に置くことができます。ページを使って、任意の量のコンテンツを整理・管理することができます。このページ機能はバージョン1.5で追加されました。

さて、WordPressページは実際どのように動作するのでしょうか?ここでは、ページとは何かを説明し、ページを使ってできることの紹介や例を挙げてみます。

この記事内で使われている用語

  • 「ページ」と普通に書かれているものは、Web上の一般的な PHP/HTML 文書を指します。
  • WordPressのページ機能で作成されたものについては、混乱を避けるために 「WordPressページ」または「ページ(太字)」と書いています。

さらに詳しい「ページ」という用語の使い方に関する話題については、「用語について」の欄をご参照ください。

WordPressページとは?

ブログの投稿は日時に深く関わったコンテンツです。特定の日時に公開され、その日時が文脈を決定します。

「WordPressページ」はそれとは異なり、サイト管理者やサイトについての情報などを公開するためによく使われます。これらの情報は日時とは関わりなく、いつでも変わらない内容となります。例えば、ある日の朝にしたことや思ったこと(例:「今日の朝ご飯はおいしかった」)を書くのには、ブログの投稿機能を使います。WordPressページには、特定の日や時間にしばられない内容(例:「このサイトでは朝ご飯に関する話題を書いています」)を書くのに使うと良いでしょう。

もちろん、あなたの WordPress はあなたのもの。どんなふうに使ってもかまいません。WordPressページを使えば、ブログの外側に置いておきたいどんな情報もサイトに加えることができます。楽しむことを忘れずに、実験したり、想像力を働かせたりして、あなたなりの使い方を見つけてください。

たとえば、ページ機能を使ってこんなコンテンツを公開することができます。

  • コピーライトや法規に関する情報、再掲載の許可、管理人の連絡先、「管理人について」、「このサイトについて」、アクセシビリティ宣言

一般的にはWordPressページと投稿は似ていると言えるでしょう。どちらにもタイトルやコンテンツがあり、サイト表示テンプレートを使って全体のデザインやレイアウトとマッチさせることができます。しかしWordPressページには、投稿にはないユニークな機能があります。

WordPressページの簡単な説明

WordPerssページとはこんなものです

  • WordPressページは、投稿に比べると日時にあまり依存しません。
  • WordPressページは、トップレベルのページとサブページに整理することができます。
  • WordPressページでは、さまざまなテンプレートファイル、 テンプレートタグ、PHPコードなどを含む「ページテンプレート」を使うことができます。

WordPerssページを誤解しないために

  • WordPressページは投稿とは別物です。ブログのメインページでは表示されず、カテゴリーを割り振ることもできません。
  • WordPressページは個別ファイルではありません。WordPressページのコンテンツは投稿と同じく、データベース内に保存されています。
  • 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 RunPHP. See also the list of Posts Formatting Plugins.)

WordPressページを作成する

To create a new Page, log in to your WordPress installation with sufficient admin privileges to create new articles, and click on the Write tab in the admin interface, which will have a Write Page tab. Clicking the Write Page tab will lead you to the page where you can create your new Page.

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.

WordPressページをサイト内からリンクする

WordPress is able to automatically generate a list of Pages on your site, for example within the sidebar, using a Template Tag called wp_list_pages(). Please see the documentation describing this tag's use 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 useful),
  • exclude (or 'hide') a Page from the list,
  • control which Pages are displayed (i.e. all Pages or just certain Sub-Pages), 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

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

if you do not have Permalinks set up, or

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

if you do have Permalinks set up.

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.

WordPressページを整理する

Just as you can have Sub-categories within your Categories, you can also have SubPages within your Pages, creating a hierarchy of 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 on travel to Africa. Then 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

To begin the process, on the Administration > Write > Write Page panel, in the upper right corner of the panel, is a drop-down box called "Page Parent". This 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 list. 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 listed, the Child Page will be nested under the Parent Page. The Permalinks of your Pages will also reflect this Page hierarchy.

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

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

WordPressページテンプレート

Individual Pages can be set to use a specific, custom Page Template that you create within your Theme. This new Page Template will then override the default page.php Page Template included with your Theme. See What Template is used to Display a Particular Page?, below, to find out exactly which Template will be used. But read what follows 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 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 Page Template available in the active theme.

デフォルトテーマのWordPressページテンプレート

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

あるWordPressページを表示する際、どのテンプレートが使われますか?

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

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

WordPressページテンプレートを作ってみよう

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
*/
?>

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.

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).

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 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 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.

WordPressページとテンプレートの例

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

アーカイブ一覧ページ

A Page Template that allows 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(); ?>

CMSとしてのWordPress

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

WordPressページをトップページとして使う

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.

When the Page is being displayed as the Home Page, 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 (eg http://example.com/home/)

WordPressページをサイト内に挿入する

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.

ブログをルート以外のディレクトリに表示させる

Suppose you have Wordpress running at http://example.com/. Suppose further 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/.

The first thing you will want to do is to create a home page. 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
*/
?>

<?php query_posts('cat=-0'); //gets all posts
    load_template( TEMPLATEPATH . '/index.php'); //loads index
 ?>

Log into 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/", ie, "/blog/%year%/%monthnum%/%postname%/". Now you have a Wordpress-managed CMS with a unique front page and logically-structured blog content.

用語について

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.

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.

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.

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, etc.).

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.