WordPress:Template Tags/Anatomy of a Template Tag

来自站长百科
Fludlen讨论 | 贡献2008年4月18日 (五) 14:40的版本
跳转至: 导航、​ 搜索

Introduction

介绍

This document provides a brief examination of the animal known as the WordPress template tag, to help those who may be new to WordPress and PHP understand what template tags are and how they're used.

这个文件提供了对animal(动物缓存),即WordPress模板标签的主要检查,帮助那些WordPress 和 PHP新手,了解模板标签是什么,和模板标签的用法。

A WordPress template tag is made up of three components:

一个WordPress模板标签是由三个部分组成的:

  • [[WordPress:#PHP_code_tag|A PHP code tag]]
  • [[WordPress:#WordPress_function|A WordPress function]]
  • [[WordPress:#Optional parameters|Optional parameters]]
  • [[WordPress:#PHP_code_tag|A PHP 代码标签]]
  • [[WordPress:#WordPress_function|一个WordPress 功能]]
  • [[WordPress:#Optional parameters|可选参数]]


These are explained below. 下面对这些进行了解释。

PHP code tag

PHP 代码标签

WordPress is built with the PHP scripting language. Though you certainly don't need to be a PHP developer to use it, knowing a little about the language can go a long way in getting the most out of WordPress. Here we provide a tiny bit of that PHP knowledge:

WordPress是以PHP脚本语言创建的。虽然你当然不需要成为一个PHP程序员来使用这个语言,但是了解一点这个语言,可以对于最有效地使用WordPress大有帮助。我们在这儿提供了一点的PHP知识:


<?php ?>

<?php ?>


The above shows the opening (<?php) and closing (?>) tag elements used to embed PHP functions and code in a HTML document, i.e. web page. There are a number of ways to embed PHP within a page, but this is the most "portable," in that it works on nearly every web server—as long as the server supports PHP (typically a document's filename also needs to end with the extension .php, so the server recognizes it as a PHP document).

以上显示了打开的(<?php)和关闭的(?>)标签元素,这些是用来在一个HTML文件,例如,网页中嵌入PHP功能和代码。在一个网页内部嵌入PHP有很多种方法,但这个方法是最"轻便的," 因为只要服务器支持PHP(通常情况下,一个文件的文件名也需要以一个扩展名.php结束,这样服务器就将它看成是一个PHP文件),这种方法几乎能在每个网络服务器&#8212上实施。

Anything within this tag is parsed and handled by the PHP interpreter, which runs on the web server (the interpreter is the PHP engine that figures out what the various functions and code do, and returns their output). For our purposes, the PHP tag lets you place WordPress functions in your page template, and through these generate the dynamic portions of your blog.

这个标签中的任何内容都由在网络服务器上运行的PHP注释器解析并处理了(注释器是PHP引擎,指出不同的功能和代码是做什么的,同时返回它们的产出)。对于我们的目的,PHP标签让你在你的网页模板上放置WordPress功能,并且通过这个来产生你的博客的动态的部分。

WordPress function

WordPress 功能

A WordPress or template function is a PHP function that performs an action or displays information specific to your blog. And like a PHP function, a WordPress function is defined by a line of text (of one or more words, no spaces), open and close brackets (parentheses), and typically a semi-colon, used to end a code statement in PHP. An example of a WordPress function is:

一个WordPress或者模板功能是一个PHP功能,它执行一个行动或者显示特别是关于你的博客的信息。与一个PHP函数相似,一个WordPress函数是由一行文本定义的(一个或者更多的单词,没有空格),打开和关闭的括号(圆括号),通常一个分号,用来结束PHP中的一个代码声明。一个WordPress函数中的一个代码如下:

the_ID();

the_ID();


the_ID() displays the ID number for a blog entry or post. To use it in a page template, you slip it into the PHP tag shown above:

the_ID()显示了一个博客条目或者文章的ID号码。在一个网页模板中使用它,你将它滑进上述所显示的PHP标签中:

<?php the_ID(); ?>

<?php the_ID(); ?>


This is now officially a WordPress template tag, as it uses the PHP tag with a WordPress function.

现在它正式是一个WordPress模板标签了,因为它在一个WordPress函数中使用PHP标签。

Optional parameters

可选参数

The final item making up a template tag is one you won't necessarily make use of unless you want to customize the tag's functionality. This, or rather these, are the parameters or arguments for a function. Here is the template function bloginfo(), with the show parameter being passed the 'name' value:

形成模板标签的最后一项,你不一定要使用,除非你想要自定义模板的功能。这个,或者这些,是一个函数的参数或者论据。下面是模板函数bloginfo(),显示的参数被通过了'name' 值:

<?php bloginfo('name'); ?>

<?php bloginfo('name'); ?>


If your blog's name is Super Weblog, the bloginfo() template tag, when using 'name' as the show parameter value, will display that name where it's embedded in your page template.

如果你的博客名是超级网络博客, bloginfo()模板标签,当将'name'用作显示参数值,就会显示名称,在它嵌入你的网页模板的位置。

Not all template tags accept parameters (the_ID() is one), and those which do accept different ones based on their intended use, so that the_content() accepts parameters separate from those which get_calendar() can be passed.

并不是所有的模板标签接受参数(the_ID() is one),那些的确接受不同的参数的,是基于他们的有意的用处。因此内容()接受的参数,与那些get_calendar()可以被通过的参数,是分开的。

Further reading

进一步阅读

See the following Codex pages for more information on WordPress templates and template tags:

看看下面的Codex网页得到更多的关于WordPress模板和模板标签的信息:

WordPress:Templates
How to Pass Tag Parameters


模板
怎样审查通过标签参数


模板:No Param 标签页脚