タグパラメータを通過する方法
http://codex.wordpress.org/Template_Tags
目次
|
序章
Introduction
テンプレートタグは、あなたがダイナミックなブログ内容を提供するためにあなたのWordPressページテンプレートに埋め込むことができるPHP機能です。そして、PHPが機能するように、多くのテンプレートタグは議論またはパラメータを受け入れます。テンプレートタグパラメータは、あなたがタグの出力を変えるか、さもなければどうにかその行動を修正するために使うことができる変数です。パラメータを、テンプレートタグが動く方法をカスタマイズすることができるユーザーオプションまたはセッティングとみなしてください。 Template tags are PHP functions you can embed in your WordPress page templates to provide dynamic blog content. And like PHP functions, many template tags accept arguments, or parameters. Template tag parameters are variables you can use to change a tag's output or otherwise modify its action in some way. Think of parameters as user options or settings that allow you to customize how a template tag works.
パラメータへの尊重で、WordPressテンプレートタグは、3つの「flavors」、それらは以下に記します: In regards to parameters, WordPress template tags come in three "flavors." These are described below:
- 1.Tags without parameters
- 2.with PHP function-style parameters
- 3.Tags with query-string-style parameters
パラメータのないタグ
Tags without parameters
若干のテンプレートタグには少しのオプションもなくて、このように、あなたが彼らに通過することができるパラメータがありません。 Some template tags do not have any options, and thus have no parameters you can pass to them.
テンプレートはthe_author_firstnameにタグを付けます()、受け入れるものはパラメータでありません。このタグは、単にポストのために著者の名前を示します。パラメータのないタグは、タグ機能の開閉ブラケット(括弧)の間で、何も持ってはいけません: The template tag the_author_firstname() is one that accepts no parameters. This tag simply displays the first name of the author for a post. Tags without parameters should have nothing between the tag function's opening and closing brackets (parentheses):
<?php the_author_firstname(); ?>
PHP機能-スタイルパラメータによるタグ
Tags with PHP function-style parameters
パラメータを受け入れることができるテンプレートタグのために、いくつかはデフォルトPHPスタイルでいることを彼らに要求します。これらのために、パラメータは一つ以上の価値を機能の括弧またはブラケットに入れることによって、タグ機能に通過されます。 For template tags that can accept parameters, some require them to be in the default PHP style. For these, parameters are passed to a tag function by placing one or more values inside the function's parentheses, or brackets.
bloginfo()、タグはあなたのブログについてどんな情報を示すべきかについて、それに話す1つのパラメータ(ショーパラメータとして知られる)を受け入れます: The bloginfo() tag accepts one parameter (known as the show parameter) that tells it what information about your blog to display:
<?php bloginfo('name'); ?>
wp_title()、タグは2つのパラメータを受け入れます:最初はsepまたはセパレーターパラメータです、そして、第2が反響または表示パラメータです: The wp_title() tag accepts two parameters: the first is the sep or separator parameter, and the second the echo or display parameter:
<?php wp_title(' - ', TRUE); ?>
最初は一重引用符に入れられます、そして、瞬間、最初がストリングと第2であるからはブールのパラメータでありません。(彼らを利用するために、パラメータタイプと方法に関する情報については、パラメータのTypesを見てください。) The first is enclosed in single-quotes and the second is not because the first is a string, and the second a boolean parameter. (See Types of parameters for information on parameter types and how to use them.)
PHP機能-スタイルパラメータのために心を閉じ込める重要な点: Important points to keep in mind for PHP function-style parameters:
- 若干の機能は、複数のパラメータをとります。
- 複数のパラメータは、コンマで区切られます。
- パラメータの順序は、重要です!
- Some functions take multiple parameters.
- Multiple parameters are separated by commas.
- The order of parameters is important!
テンプレートタグの機能にパラメータを通過するとき、あなたがあなたが修正したい最後のものまですべてのパラメータのために価値を指定することを確認してください、さもなければ、タグは予想通りに動かないかもしれません。たとえば、テンプレートはget_archivesにタグを付けます()、6つのパラメータを持ちます: When passing parameters to a template tag's function, make sure you specify values for all parameters up to the last one you wish to modify, or the tag may not work as expected. For example, the template tag get_archives() has six parameters:
<?php get_archives('type', 'limit', 'format', 'before',
'after', show_post_count); ?>
表示にとって、アーカイブはあなたが望む習慣をリストします、あなたが第3(フォーマット)と第5の(後に)パラメータを修正する必要があるだけであると言いましょう。こうするために、あなたも、同様に、最初で、第2で、第4のパラメータのためにデフォルト値に入ることは確実にする必要があります: To display the archives list the way you want, let's say you only need to modify the third (format) and fifth (after) parameters. To do this, you also need to make sure to enter default values for the first, second and fourth parameters, as well:
<?php get_archives( , , 'custom', , '
'); ?>
それらの特定のパラメータのためにこの場合デフォルトを強制する空のパラメータ価値を意味するために、一重引用符の使用に気がついてください。テキストの列を指定しているパラメータで本当であるように、空のパラメータを通過するとき、デフォルトが上書きされることができるのでご了承ください、そして、空のブールの値を超える方法がありません。それで、パラメータのデフォルトのためにドキュメンテーションをチェックしてください、そして、人が指定されるとき、あなたのパラメータ価値(また、パラメータタイプに関する情報については、パラメータのTypesを見ます)としてそれを使ってください。第6のパラメータはやめられました;これは、WordPressが明らかでないままにされるどんな残りのパラメータのためにでもデフォルトを使うからです。 Notice the use of single-quotes to denote empty parameter values, which in this case forces defaults for those specific parameters. Be aware that defaults can be overwritten when passing empty parameters, as is the case of a parameter specifying a string of text, and there's no way to pass an empty boolean value. So check the documentation for a parameter's default, and when one is specified use it as your parameter value (also see Types of parameters for information on parameter types). The sixth parameter was left off; this is because WordPress uses the default for any remaining parameters left unspecified.
必ず慎重にテンプレートタグのためにドキュメンテーションに続くようにするようにしてください、そして、テンプレート機能が予想する順序であなたのパラメータを置いてください。最後に、テンプレートタグですべてのパラメータのためにデフォルトを使うために、指定されるパラメータ価値なしで、タグを使用してください: Make sure to follow the documentation for a template tag carefully, and place your parameters in the order the template function expects. Finally, to use the defaults for all parameters in a template tag, use the tag with no parameter values specified:
<?php get_archives(); ?>
質問-ストリングスタイルのパラメータによるタグ
Tags with query-string-style parameters
テンプレートタグの最後のタイプは、タグにパラメータを通過する質問-ストリングスタイルと呼ばれていることを利用します。これらは、便利な'wrapper'をPHP関数パラメータスタイルを使用して、比較的かなりの数のパラメータがあるタグに提供します。たとえば、テンプレートはwp_list_cats()にタグを付けますlist_cats()への包装紙です、18のパラメータによるタグ!
The last type of template tag makes use of what's called a query-string style to pass parameters to the tag. These provide a convenient 'wrapper' to tags which use the PHP function parameter style and have a relatively large number of parameters. For example, the template tag wp_list_cats() is a wrapper to list_cats(), a tag with eighteen parameters!
あなたが固まりたい、除外しますlist_cats()でパラメータ(パラメータリストの第17)、そして、彼らのデフォルトで残りを残してください、あなたはこうしなければなりません: If you want to set the exclude parameter in list_cats() (seventeenth in the parameter list) and leave the rest at their defaults, you have to do this:
<?php list_cats(TRUE, 'All', 'ID', 'asc', , TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, , , FALSE, , , '10,11,12'); ?>
または、あなたはwp_list_cats()を使うことができます: Or you can use wp_list_cats():
<?php wp_list_cats('exclude=10,11,12'); ?>
彼らがあなたにちょうどそれらのパラメータの価値を変えさせたという点で質問-ストリングスタイルタグが役に立つように、価値を全員またはほぼ彼ら全員に提供する必要があることなく、あなたは要求します。しかし、すべてのPHP機能-スタイルテンプレートタグが、質問-ストリングスタイルを等しくするというわけではありません。(また、質問-ストリングを受け入れるタグの名前が通常パラメータと呼ぶメモは『wp_』接頭辞から始めます、wp_list_cats()のような、しかし、あるとしても、パラメータを受け入れるその方法を確かめるために、タグでドキュメンテーションをチェックしてください。) So query-string style tags are useful in that they let you change the values of just those parameters you require, without needing to provide values for all or nearly all of them. However, not all PHP function-style template tags have a query-string style equivalent. (Also note that names for tags that accept query-string style parameters usually start with a 'wp_' prefix, such as wp_list_cats(), but check the documentation on a tag to verify its method for accepting parameters, if any.)
タグwp_list_authors()、我々が3をここでセットした6つのパラメータを持ちます: The tag wp_list_authors() has six parameters, of which we set three here:
<?php wp_list_authors('show_fullname=1&feed=rss&optioncount=1'); ?>
最初に、パラメーターはすべて、一方の単一あるいはダブルクォートによってともに囲まれます。その後、これらがアンパサンド(&)で分離されている一方、パラメーターはそれぞれパラメーター=値フォーマットに入力されます。分類されて、上に示されるようなタグは次のように述べます: First, all the parameters together are enclosed by either single or double quotes. Then each parameter is entered in the parameter=value format, while these are separated with an ampersand (&). Broken down, the tag as shown above states:
- パラメーターshow_fullname(ブールのタイプ・パラメーター)は1(真実)と等しい。
- Parameter show_fullname (a boolean type parameter) equals 1 (true).
AND
- パラメーター材料(ストリングのタイプ・パラメーター)同等のものrss。
- Parameter feed (a string type parameter) equals rss.
AND
- パラメーターoptioncount(ブールのタイプ・パラメーター)は1(真実)と等しい。
- Parameter optioncount (a boolean type parameter) equals 1 (true).
(パラメーター・タイプ、およびそれらを使用する方法についての情報に関しては、パラメーターのタイプを参照。) (See Types of parameters for information on parameter types and how to use them.)
Parameters in the query-string style do not have to be entered in a specific order. The only real concern is assuring parameter names are spelled correctly. If legibility is a problem, you can separate parameters with a space:
<?php wp_list_authors('show_fullname=1 & feed=rss & optioncount=1'); ?>
You can also spread a query-string over several lines (note the specific format of enclosing each parameter/value pair in single quotes and a dot starting each new line):
<?php wp_list_authors(
'show_fullname=1'
.'&feed=rss'
.'&optioncount=1'
); ?>
There are a few limitations when using query-string style tags, among which you cannot pass certain characters, such as the ampersand or a quote mark (single or double). In those cases, you can use an associative array:
<?php $params = array( 'type' => 'postbypost',
'limit' => 5,
'format' => 'custom',
'before' => '- 1 = TRUE = true
- 0 = FALSE = false

