站长百科 | 数字化技能提升教程 数字化时代生存宝典
首页
数字化百科
电子书
▼
建站程序
开发
服务器
办公软件
开发教程
▼
服务器教程
软件使用教程
运营教程
热门电子书
▼
CSS教程
WordPress教程
导航
程序频道
推广频道
网赚频道
人物频道
网站程序
网页制作
云计算
服务器
CMS
论坛
网店
虚拟主机
cPanel
网址导航
WIKI使用导航
WIKI首页
热点词条
最新资讯
网站程序
站长人物
页面分类
使用帮助
编辑测试
创建条目
网站地图
站长百科导航
站长百科
主机侦探
IDCtalk云说
跨境电商导航
WordPress啦
站长专题
网站推广
网站程序
网站赚钱
虚拟主机
cPanel
网址导航专题
云计算
微博营销
虚拟主机管理系统
开放平台
WIKI程序与应用
美国十大主机
编辑“
Theme Development
”(章节)
人物百科
|
营销百科
|
网赚百科
|
站长工具
|
网站程序
|
域名主机
|
互联网公司
|
分类索引
跳转至:
导航
、
搜索
警告:
您没有登录。如果您做出任意编辑,您的IP地址将会公开可见。如果您
登录
或
创建
一个账户,您的编辑将归属于您的用户名,且将享受其他好处。
反垃圾检查。
不要
加入这个!
===='''以查询为基础的模板'''==== 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:版权
的细节)。
未经许可,请勿提交受版权保护的作品!
取消
编辑帮助
(在新窗口中打开)