此部分标签函数主要涉及到与博客相关的信息、页面标题、文章归档、页面列表 文章查询等。
WordPress 普通模板标签(General Template Tags)主要包含下列内容:
- Blog Info (博客信息)
- Blog Info RSS (用于syndication feeds)
- Blog Info (PHP) (博客信息)
- Blog Info RSS (PHP) (用于syndication feeds)
- Page Title (页面标题)
- Get Posts (获取文章)
- Archieves List (文章归档列表)
- Page Link List (页面链接列表)
- Page DropDown (页面下拉菜单)
- Login/Loginout Link (登录/注销链接)
- Register/Site Admin Link (注册/管理链接)
- Query Posts (查询文章)
- RSS Enclosures (用于播客)
- Tag Cloud (标签云)
- Search Query (搜索查询)
1. Blog Info (博客信息)
显示有关博客的信息。
用法:<?php bloginfo(‘arguments’); ?>。
参数说明:
- name:博客名称
- description:博客描述
- url:博客站点链接
- rdf_url:RDF/RSS 1.0 feed 链接
- rss_url:RSS 0.92 feed 链接
- rss2_url:RSS 2.0 Feed 链接
- atom_url:Atom feed 链接
- comments_rss2_url:评论RSS 2.0 链接
- pingback_url:Pingback (XML-RPC file) 链接
- admin_email:管理员用户邮箱
- charset:博客字符编码
- version:WordPress版本号
- html_type:博客的Content-type
- wpurl:WordPress安装链接
- template_url:当前使用的模板的URL
- template_director:当前使用的模板的目录URL
- stylesheet_url:样式表URL
2. Blog Info RSS(用于syndication feeds)
用于RSS,显示有关博客的信息。
用法:<?php bloginfo_rss(‘arguments’); ?>。
参数说明:
- name:博客名称
- description:博客描述
- url:博客站点链接
- rdf_url:RDF/RSS 1.0 feed 链接
- rss_url:RSS 0.92 feed 链接
- rss2_url:RSS 2.0 Feed 链接
- atom_url:Atom feed 链接
- comments_rss2_url:评论RSS 2.0 链接
- pingback_url:Pingback (XML-RPC file) 链接
- admin_email:管理员用户邮箱
- charset:博客字符编码
- version:WordPress版本号
- html_type:博客的Content-type
- wpurl:WordPress安装链接
- template_url:当前使用的模板的URL
- template_director:当前使用的模板的目录URL
- stylesheet_url:样式表URL
3. Blog Info PHP(用于syndication feeds)
返回供PHP使用的有关博客的信息。
用法:<?php get_bloginfo(‘arguments’); ?>。
参数说明:
- name:博客名称
- description:博客描述
- url:博客站点链接
- home:博客站点链接
- siteurl:博客站点链接
- wpurl:WordPress安装链接
- rdf_url:RDF/RSS 1.0 feed 链接
- rss_url:RSS 0.92 feed 链接
- rss2_url:RSS 2.0 Feed 链接
- atom_url:Atom feed 链接
- comments_rss2_url:评论RSS 2.0 链接
- pingback_url:Pingback (XML-RPC file) 链接
- stylesheet_url:样式表URL
- stylesheet_directory:样式表目录
- template_directory:模板目录
- template_url:模板URL
- admin_email:管理员邮箱
- charset:字符编码
- version:WordPress版本号
- html_type:博客的Content-type
4. Blog Info RSS(PHP)(用于syndication feeds)
用于RSS,返回供PHP使用的有关博客的信息。
用法:<?php get_bloginfo_rss(‘arguments’); ?>。
参数说明:
- name:博客名称
- description:博客描述
- url:博客站点链接
- home:博客站点链接
- siteurl:博客站点链接
- wpurl:WordPress安装链接
- rdf_url:RDF/RSS 1.0 feed 链接
- rss_url:RSS 0.92 feed 链接
- rss2_url:RSS 2.0 Feed 链接
- atom_url:Atom feed 链接
- comments_rss2_url:评论RSS 2.0 链接
- pingback_url:Pingback (XML-RPC file) 链接
- stylesheet_url:样式表URL
- stylesheet_directory:样式表目录
- template_directory:模板目录
- template_url:模板URL
- admin_email:管理员邮箱
- charset:字符编码
- version:WordPress版本号
- html_type:博客的Content-type
5. Page Title (页面标题)
返回页面标题。
用法:<?php wp_title(‘sep’, echo, ‘seplocation’); ?>。
参数说明:
- sep:在标题前面或后面显示分隔文本,默认值为» (») 。
例如:<?php wp_title(‘•’, echo, ‘seplocation’); ?>。
- echo:1 | 0,输出或返回供PHP使用。
例如:<?php wp_title(‘sep’, 1, ‘seplocation’); ?>。
- seplocation:指定sep是在标题的左边还是右边,除非指定seplocation=right,否则sep都将放置在标题的前面。
例如:<?php wp_title(‘sep’, echo, ‘right’); ?>。
6. Get Posts (获取文章)
用法:<?php get_posts(‘arguments’); ?>。
参数说明:
- numberposts:返回指定数量的文章,默认值=5。
例如:<?php get_posts(‘numberposts=10’); ?>。
- offset:偏移量,默认值=0。
例如:<?php get_posts(‘offset=1’); ?>。
- category:显示指定category ID目录下的文章。
例如:<?php get_posts(‘category=2’); ?>。
- orderby:根据指定字段排序。
例如:<?php get_posts(‘orderby=post_name’); ?>
- order:升序 | 降序。
例如:<?php get_posts(‘order=DESC’); ?>
- include:包含指定ID的文章,ID之间按逗号”,”或空格 ” “分割。
例如:<?php get_posts(‘include=62’); ?>
- exclude:排除指定ID的文章,ID之间按逗号”,”或空格 ” “分割。
例如:<?php get_posts(‘include=62’); ?>
- meta_key 和 meta_value:只显示含有自定义字段meta_key和meta_value的文章。
例如:<?php get_posts(‘meta_key=sport&meta_value=basketball’); ?>。
- post_type:post | page | attachment |
- all post types | (空客)
显示指定类型的文章。
例如:<?php get_posts(‘post_type=page’); ?>
- post_status:publish | private | draft | future | (空格)
显示指定状态的文章。
<?php get_posts(‘post_status=draft’); ?>
- post_parent : 显示指定目录下的文章。
例如:<?php get_posts(‘post_parent=7’); ?>
7. Archieves List (文章归档列表)
用法:<?php wp_get_archives(‘arguments’); ?>
参数说明:
- type:yearly | monthly | daily | weekly | postbypost
例如:<?php wp_get_archives(‘type=yearly’); ?>。
- limit:归档链接数量
例如:<?php wp_get_archives(‘limit=5’); ?>。
- format:html | option | link | custom
用法:<?php wp_get_archives(‘format=link’); ?
参数值说明:
- html:列表的形式,使用<li>标签
- option:选择项形式,使用<select>,<option>标签
- link:使用link()函数
- custom:自定义格式
- before:在format为html或custom格式时,需要放置到链接前面的文本
用法:<?php wp_get_archives(‘before=»’); ?>。
- after:在format为html或custom格式时,需要放置到链接后面的文本
用法:<?php wp_get_archives(‘after=«’); ?>。
- show_post_count:1 | 0显示归档文件中所包含的文章数量。
用法:<?php wp_get_archives(‘show_post_count=1’); ?>。
8. Page Link List (页面链接列表)
用法:<?php wp_list_pages(‘arguments’); ?>
参数说明:
- sort_column:post_title | menu_order | post_date | post_modified | ID | post_author | post_name
用法:<?php wp_list_pages(‘sort_column=ID’); ?>。
- sort_order:asc | desc
用法:<?php wp_list_pages(‘sort_order=desc’); ?>。
- exclude:排除指定ID的文章,ID之间以逗号分隔。
用法:<?php wp_list_pages(‘exclude=62’); ?>。
- include:包含指定ID的文章。
用法:<?php wp_list_pages(‘include=62’); ?>。
- depth:0 | -1 | 1 | 2 | … 文章层级深度
参数值说明:
- 0:按层级结构(有缩进)显示页面及子页面
- -1:所有页面平级显示
- 1:值显示顶级页面
- 2或更大:显示不大于指定深度或层级的页面
- child_of:显示指定页面的子页面
用法:<?php wp_list_pages(‘child_of=7’); ?>。
- show_date:空值 | modified | 其他
用法:<?php wp_list_pages(‘showdate=modified’); ?>。
参数值说明:
- 空值:默认不显示日期
- modified:最后修改日期
- 其他:显示文章发表时的日期
- date_format:
用法: <?php wp_list_pages(‘date_format=l, F j, Y’); ?>。
- title_li:页面列表标题的文本及样式
用法: <?php wp_list_pages(‘title_li=Page List’); ?>。
- echo:1 | 0 ,输出页面链接列表或返回供PHP适用的html列表项
用法:<?php wp_list_pages(‘echo=0’); ?>。
- hierarchial:1 | 0 ,子页面显示方式,如果 hierarchial=1,则子页面以缩进的形式显示
<?php wp_list_pages(‘hierarchial=0’); ?>。
- meta_key and meta_value:只显示带有 meta_key 和 meta_value 的页面
用法: <?php wp_list_pages(‘meta_key=sport&meta_value=basketball’); ?>。
9 . Page DropDown (页面下拉菜单),以不带提交按钮的下拉菜单形式显示
用法:<?php wp_dropdown_pages(‘arguments’); ?>。
参数说明:
- depth:0 | -1 | 1 | n
用法:<?php wp_dropdown_pages(‘depth=1’); ?>。
- child_of:指显示指定ID下的子页面
用法:<?php wp_dropdown_pages(‘child_of=4’); ?>。
- selected:下来菜单中选定指定ID的页面,默认不选定
用法:<?php wp_dropdown_pages(‘selected=7’); ?>。
- echo:1 | 0 ,显示链接列表或返回共PHP使用的HTML列表项
用法:<?php wp_dropdown_pages(‘echo=0’); ?>。
- name:下来列表项的名称,默认值为page_id
用法:<?php wp_dropdown_pages(‘name=page-id’); ?>。
- show_option_none:下来列表项默认空选项
用法:<?php wp_dropdown_pages(‘show_option_none=’); ?>
- exclude:排出指定目录ID所属页面,以逗号分割目录ID
用法:<?php wp_dropdown_pages(‘exclude=7,3’); ?>。
10. Login/Loginout Link (登录/注销链接)
用法:<?php wp_loginout(); ?>,显示登陆链接,如果已登陆,则显示注销链接。
11. Register/Site Admin Link (注册/管理链接),显示注册链接,如果已登陆,则显示注销链接
用法:<?php wp_register(‘before’, ‘after’); ?>。
参数说明:
- before:<li> | 其他字符,链接项前导符。
用法:<?php wp_register(‘»’, ‘after’); ?>。
- after:</li> | 其他字符,链接项前导符。
用法:<?php wp_register(‘before’, ‘«’); ?>。
12. Query Posts (查询文章)
用法:<?php query_posts(‘parameters’); ?>。
参数说明:
- cat:显示指定ID目录下的文章
用法:<?php query_posts(‘cat=7’); ?>。
- category_name,显示指定目录名称下的文章
用法:<?php query_posts(‘category_name=Sports’); ?>。
- tag:显示指定标签下的文章
用法:<?php query_posts(‘tag=basketball’); ?>。
- author_name:显示指定作者名称下的文章
用法:<?php query_posts(‘author_name=Chase’); ?>。
- author:显示指定作者ID下的文章
用法:<?php query_posts(‘author=3’); ?>。
- p:根据 post ID 指定头条文章
用法:<?php query_posts(‘p=9’); ?>。
- name:根据 post slug 指定头条文章
用法:<?php query_posts(‘name=chase-crawford’); ?>。
- page_id:根据ID,显示页面文章
用法:<?php query_posts(‘page_id=11’); ?>。
- pagename:根据页面名称,显示页面文章
用法:<?php query_posts(‘pagename=about’); ?>。
- showposts:文章数量
用法:<?php query_posts(‘showposts=11’); ?>。
- hour:显示指定小时内文章
用法:<?php query_posts(‘hour=12’); ?>。
- minute:显示指定分钟内的文章
用法:<?php query_posts(‘minutes=33’); ?>。
- second:显示指定秒内的文章
用法:<?php query_posts(‘second=59’); ?>。
- day:显示指定天数内的文章
用法:<?php query_posts(‘day=14’); ?>。
- monthnum:显示指定月份的文章
用法:<?php query_posts(‘monthnum=6’); ?>。
- year:显示指定年内的文章
用法:<?php query_posts(‘year=2003’); ?>。
- paged
用法:<?php query_posts(‘paged=3’); ?>。
- posts_per_page:每页显示的文章数
用法:<?php query_posts(‘post_per_page=5’); ?>。
- order:ASC | DESC 排序方式
用法:<?php query_posts(‘order=ASC’); ?>。
- offset:偏移
用法:<?php query_posts(‘offset=1’); ?>。
- orderby:排序类别
用法:<?php query_posts(‘orderby=title’); ?>。
13. RSS Enclosures (用于播客)
用法:<?php rss_enclosure(); ?>。
14. Tag Cloud (标签云)
用法:<?php wp_tag_cloud(”); ?>,显示标签。
15. Search Query (搜索查询)
用法:<?php the_search_query(”); ?>,返回搜索查询结果。