站长百科 | 数字化技能提升教程 数字化时代生存宝典
首页
数字化百科
电子书
▼
建站程序
开发
服务器
办公软件
开发教程
▼
服务器教程
软件使用教程
运营教程
热门电子书
▼
CSS教程
WordPress教程
导航
程序频道
推广频道
网赚频道
人物频道
网站程序
网页制作
云计算
服务器
CMS
论坛
网店
虚拟主机
cPanel
网址导航
WIKI使用导航
WIKI首页
热点词条
最新资讯
网站程序
站长人物
页面分类
使用帮助
编辑测试
创建条目
网站地图
站长百科导航
站长百科
主机侦探
IDCtalk云说
跨境电商导航
WordPress啦
站长专题
网站推广
网站程序
网站赚钱
虚拟主机
cPanel
网址导航专题
云计算
微博营销
虚拟主机管理系统
开放平台
WIKI程序与应用
美国十大主机
编辑“
Theme Development
”(章节)
人物百科
|
营销百科
|
网赚百科
|
站长工具
|
网站程序
|
域名主机
|
互联网公司
|
分类索引
跳转至:
导航
、
搜索
警告:
您没有登录。如果您做出任意编辑,您的IP地址将会公开可见。如果您
登录
或
创建
一个账户,您的编辑将归属于您的用户名,且将享受其他好处。
反垃圾检查。
不要
加入这个!
===主题模板文件=== [[WordPress:Stepping Into Templates|Templates]] are PHP source files used to generate the pages requested by visitors. Let's look at the various templates that can be defined as part of a Theme. [[WordPress:Stepping Into Templates|模板]]是PHP原始文件,根据访客要求,用来产生网页的。让我们来看看可以被定义为主题部分的不同的模板。 WordPress allows you to define separate templates for the various aspects of your weblog; however, it is not essential to have all these different template files for your blog to function fully. Templates are chosen and generated based upon the [[WordPress:Template Hierarchy]], depending upon what templates are available in a particular Theme. As a Theme developer, you can choose the amount of customization you want to implement using templates. For example, as an extreme case, you can use only one template file, called <tt>index.php</tt> as the template for ''all'' pages generated and displayed by the weblog. A more common use is to have different template files generate different results, to allow maximum customization. WordPress能够使你为你的博客的不同部分分别定义模板;然而,使你的博客正常地运行,并不一定需要所有的这些不同的模板文件。模板是根据[[WordPress:Template Hierarchy|模板层级]]选择和产生的,取决于特别的主题中拥有什么样的模板。作为一个主题开发者,你可以选择你想使用模板,自定义多少内容。例如,一个极端的例子,你可以为网络日志上产生的和显示的''所有的''网页,只使用一个称为<tt>index.php</tt>模板文件,作为模板。一个更加通常的用法是使用不同的模板文件产生不同的结果,允许最大化的自定义。 ===='''Basic Templates'''==== ===='''基本的模板'''==== At the very minimum, a WordPress Theme consists of two files: 在最小值的时候, WordPress主题包含有两个文件: * <tt>style.css</tt> * <tt>index.php</tt> * <tt>style.css</tt> * <tt>index.php</tt> Both of these files go into the Theme's directory. The <tt>index.php</tt> [[WordPress:Stepping Into Templates|template file]] is very flexible. It can be used to include all references to the header, sidebar, footer, content, categories, archives, search, error, and other web pages generated by the user on your site. Or it can be ''subdivided'' into modular template files, each one taking on part of the workload. 这两个文件都归属于主题的目录。<tt>index.php</tt> [[WordPress:Stepping Into Templates|模板文件]]非常地灵活。它可以被用来包括关于标题,工具条,页脚,内容,类别,归档,搜索,错误和你的站点上的用户创建的其它的网页的所有参数。或者它可以被''再次地分''到模模板文件,每个部分都具有一部分的工作量。 If you do not provide any other template files, WordPress will use the built-in default files. For example, if you do not have either a <tt>comments.php</tt> or <tt>comments-popup.php</tt> template file, then WordPress will automatically use the <tt>wp-comments.php</tt> and <tt>wp-comments-popup.php</tt> template files using [[WordPress:Template Hierarchy]]. These default templates may not match your Theme very well, so you probably will want to provide your own. The basic files normally used to subdivide (which go into the Theme's directory) are: 如果你没有提供其它任何的模板文件,WordPress会使用内置的默认文件。例如,如果你既没有<tt>comments.php</tt>也没有<tt>comments-popup.php</tt>模板文件,WordPress就会使用[[WordPress:Template Hierarchy|模板层级]],自动地使用<tt>wp-comments.php</tt> 和<tt>wp-comments-popup.php</tt>模板文件。这些默认模板可能不太匹配你的主题,因此你可能需要提供你自己的模板。用来再次地切分的基本的文件(归属于主题的目录)是: * <tt>header.php</tt> * <tt>sidebar.php</tt> * <tt>footer.php</tt> * <tt>comments.php</tt> * <tt>comments-popup.php</tt> * <tt>header.php</tt> * <tt>sidebar.php</tt> * <tt>footer.php</tt> * <tt>comments.php</tt> * <tt>comments-popup.php</tt> Using these modular template files, you can put template tags within the <tt>index.php</tt> master file to include or ''get'' these units where you want them to appear in the final generated web page. 使用这些模的模板文件,你可以将这些模板标签放到<tt>index.php</tt>主要文件中来包括或者''得到''这些units,你想让它们出现在最后产生的网页的位置。 * To include the header, use the <tt>[[WordPress:Include Tags#The Header Template|get_header()]]</tt> template tag. *要包含标题,请使用<tt>[[WordPress:Include Tags#The Header Template|get_header()]]</tt>模板标签。 * To include the sidebar, use the <tt>[[WordPress:Include Tags#The Sidebar Template|get_sidebar()]]</tt> template tag. *要包含工具条,使用<tt>[[WordPress:Include Tags#The Sidebar Template|get_sidebar()]]</tt>模板标签。 * To include the footer, use the <tt>[[WordPress:Include Tags#The Footer Template|get_footer()]]</tt> template tag. *要包含页脚,使用<tt>[[WordPress:Include Tags#The Footer Template|get_footer()]]</tt> 模板标签。 Here is an example of the ''include'' usage: 下面是关于''包含'' 用法的一个例子: <pre><?php get_sidebar(); ?> <?php get_footer(); ?></pre> <pre><?php get_sidebar(); ?> <?php get_footer(); ?></pre> For more on how these various Templates work and how to generate different information within them, read the [[WordPress:Templates]] documentation. 关于这些不同模板怎样运行以及怎样在模板里面产生不同信息的更多内容,请阅读[[WordPress:Templates|模板]]文件。 ===='''Query-based Templates'''==== ===='''以查询为基础的模板'''==== WordPress can load different [[WordPress:Stepping Into Templates|Templates]] for different ''query'' types. There are two ways to do this: as part of the built-in [[WordPress:Template Hierarchy]], and through the use of [[WordPress:Conditional Tags]] within [[WordPress:The Loop]] of a template file. WordPress可以为不同的''查询'' 形式载入不同的[[WordPress:Stepping Into Templates|模板]]。有两种方法可以做到这一点:作为内置的[[WordPress:Template Hierarchy|模板层级]]的一部分,通过在模板文件的[[WordPress:The Loop|Loop]]中使用[[WordPress:Conditional Tags|条件式标签]]。 To use the [[WordPress:Template Hierarchy]], you basically need to provide special-purpose Template files, which will automatically be used to override <tt>index.php</tt>. For instance, if your Theme provides a template called <tt>category.php</tt> and a category is being queried, <tt>category.php</tt> will be loaded instead of <tt>index.php</tt>. If <tt>category.php</tt> is not present, <tt>index.php</tt> is used as usual. 要使用[[WordPress:Template Hierarchy|模板层级]],你只要提供特殊用途的模板文件,这个文件会自动地覆盖<tt>index.php</tt>。例如,如果你的主题提供一个叫做<tt>category.php</tt>的模板,并且提供一个正被查询的类别,<tt>category.php</tt>而不是<tt>index.php</tt>将会被载入。如果<tt>category.php</tt>没有出现,<tt>index.php</tt>会照常使用。 You can get even more specific in the Template Hierarchy by providing a file called, for instance, <tt>category-6.php</tt> -- this file will be used rather than <tt>category.php</tt> when generating the page for the category whose ID number is 6. (You can find category ID numbers in [[WordPress:Administration_Panels#Manage_-_Change_your_content|Manage]] > [[WordPress:Administration_Panels#Categories|Categories]] if you are logged in as the site administrator in WordPress version 2.3 and below. In WordPress 2.5 the ID column was removed from the Admin panels. You can locate the category id by clicking 'Edit Category' and looking on the URL address bar for the cat_ID value. It will look '...categories.php?action=edit&cat_ID=3' where '3' is the category id). For a more detailed look at how this process works, see [[WordPress:Category Templates]]. 通过提供一个例如,称作<tt>category-6.php</tt>的文件,你可以在模板层级中得到更加详细的信息---当为一个ID号码为6的类别产出网页的时候,这个文件而不是<tt>category.php</tt>会被用到。(如果你在WordPress2.3版本以及更低的版本中,以站点管理员的身份登录,你在 [[WordPress:Administration_Panels#Manage_-_Change_your_content|管理]] > [[WordPress:Administration_Panels#Categories|类别]] 下面会看到这个类别的ID数字。在WordPress 2.5版本中,管理面板中移除了ID栏。通过点击'编辑类别' ,并且查找URL地址中的cat_ID 参数值,你可以查找类别id的位置。看起来就像'...categories.php?action=edit&cat_ID=3' 其中'3'就是类别 id)。更详细地看看这个过程是怎样进行的,请看看[[WordPress:Category Templates|类别模板]]。 If your Theme needs to have even more control over which Template files are used than what is provided in the [[WordPress:Template Hierarchy]], you can use [[WordPress:Conditional Tags]]. The Conditional Tag basically checks to see if some particular condition is true, within the [[WordPress:The_Loop_in_Action|WordPress Loop]], and then you can load a particular template, or put some particular text on the screen, based on that condition. 如果你的主题需要更多地控制使用的哪个模板文件而不是[[WordPress:Template Hierarchy|模板层级]]中所提供的内容,你可以使用[[WordPress:Template Hierarchy|条件式标签]]。条件式标签基本上是用来检查看看在[[WordPress:The_Loop_in_Action|WordPress Loop]]内的,一些特别的条件是否是真的,然后你就可以根据那个情况,载入一个特别的模板,或者在屏面上放一些特别的文本。 For example, to generate a distinctive style sheet in a post only found within a specific category, the code might look like this: 例如,给一个特别类别中的文章创建一个样式表,代码可能看起来像这样的: <pre><?php if (is_category(9)) { // looking for category 9 posts include(TEMPLATEPATH . '/single2.php'); } else { // put this on every other category post include(TEMPLATEPATH . '/single1.php'); } ?></pre> <pre><?php if (is_category(9)) { //查找类别9中的文章 包括(TEMPLATEPATH . '/single2.php'); } else { // 每隔一篇文章便放入这个 include(TEMPLATEPATH . '/single1.php'); } ?></pre> Or, using a query, it might look like this: 或者,使用一个查询,这个查询可能看起来像: <pre><?php $post = $wp_query->post; if ( in_category('9') ) { include(TEMPLATEPATH . '/single2.php'); } else { include(TEMPLATEPATH . '/single1.php'); } ?></pre> <pre><?php $post = $wp_query->post; if ( in_category('9') ) { include(TEMPLATEPATH . '/single2.php'); } else { include(TEMPLATEPATH . '/single1.php'); } ?></pre> In either case, this example code will cause different templates to be used depending on the category of the particular post being displayed. Query conditions are not limited to categories, however -- see the [[WordPress:Conditional Tags]] article to look at all the options. 在上述任一例子中,代码会产生不同的模板,这些模板的使用取决于类别上显示的文章。查询条件并不局限于类别,然而—请看看[[WordPress:Conditional Tags|条件式标签]]文章来看看所有的选项。
摘要:
请注意,您对站长百科的所有贡献都可能被其他贡献者编辑,修改或删除。如果您不希望您的文字被任意修改和再散布,请不要提交。
您同时也要向我们保证您所提交的内容是您自己所作,或得自一个不受版权保护或相似自由的来源(参阅
Wordpress-mediawiki:版权
的细节)。
未经许可,请勿提交受版权保护的作品!
取消
编辑帮助
(在新窗口中打开)