您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

模板标签:Tuts+ 指南继续

2025/8/12 8:28:10发布28次查看
在本系列的第二部分中,我们介绍了第一批 wordpress 模板标签。在第三部分中,我们将介绍第二批近 200 个模板标签。在整个教程中,我们将看到有关分类法和术语的模板标签。
获取类别的描述:category_description()此模板标记返回类别的描述。
参数此模板标记仅接受一个参数:
$category_id (可选—整数):类别id。
(默认:查询的类别) >
用法<?php$cat_desc = get_category_description( 15 );?>
获取标签的描述:tag_description()此模板标记返回标记的描述。
参数此模板标记仅接受一个参数:
$tag_id (可选 - 整数):
标签的 id。
(默认:当前标签)用法<?php// display the description of current tag.echo tag_description();// get the description of a specific tag.$special_tag_desc = tag_description( 42 );?>
获取术语的描述:term_description()此模板标记仅返回术语的描述。
参数此模板标记接受两个参数:
$term_id (可选 - 整数):
术语的 id。
(默认:当前术语) $taxonomy (可选—字符串):
术语的分类。
(默认:'post_tag') >用法<?php// display the description of current term.echo term_description();// get the description of a specific term from a specific taxonomy.$special_term_desc = term_description( 14, 'laptop_inches' );?>
获取并显示类别档案的页面标题:single_cat_title()此模板标记返回并显示类别的标题,以便在页面标题中使用。
参数此模板标记接受两个参数:
$prefix (可选—字符串):
标题前缀。
(默认:空) $echo (可选 - 布尔值):
是否 echo (true) 或返回 (false) 标签。
(默认:true)用法<?php// display the category title with a prefix.single_cat_title( 'category: ' );// get the category title.$cat_title = single_cat_title( '', false );?>
获取并显示标签档案的页面标题:single_tag_title()此模板标记返回并显示标记的标题,以便在页面标题中使用。
参数此模板标记接受两个参数:
$prefix (可选—字符串):
标题前缀。
(默认:空) $echo (可选 - 布尔值):
是否 echo (true) 或返回 (false) 标签。
(默认:true)用法<?php// display the tag title with a prefix.single_tag_title( 'tag archive: ' );// get the tag title.$tag_title = single_tag_title( '', false );?>
获取并显示术语档案的页面标题:single_term_title()此模板标记返回并显示在页面标题中使用的术语标题。
参数此模板标记接受两个参数:
$prefix (可选—字符串):
标题前缀。
(默认:空) $echo (可选 - 布尔值):
是否 echo (true) 或返回 (false) 标签。
(默认:true)用法<?php// display the term title with a prefix.single_term_title( 'term archive: ' );// get the term title.$term_title = single_term_title( '', false );?>
获取并显示帖子的类别:get_the_category_list() & the_category()这些模板标签获取并输出分配给帖子的类别。
参数两个模板标签都接受三个参数:
$separator (可选—字符串):
分隔符文本。
(默认:空—如果此参数为空,则函数将返回并显示类别的无序列表) $parents (可选—字符串):
如何显示父类别(“多个”、“单个”或空)。
(默认:空) $post_id (可选 - 整数):
帖子 id。
(默认:当前帖子)用法<?php// get an unordered list of current post's categories.get_the_category_list();// display current post's categories separated by commas and with their parents (if there are any).the_category( ', ', 'multiple' );?>
获取并显示提要帖子的类别: get_the_category_rss() & the_category_rss()这些模板标签使分配给帖子的类别准备好供提要并返回或显示它。
参数两个模板标签只接受一个参数:
$feed_type (可选 - 字符串):
提要类型。
(默认:默认提要类型)用法<?php// get feed items of categories for the default feed type.get_the_category_rss();// display feed items of categories for atom feeds.the_category_rss( 'atom' );?>
获取并显示帖子的标签:get_the_tag_list() & the_tags()这些模板标签返回或显示您帖子的标签。
参数两个模板标签都接受三个参数:
$before (可选 — 字符串):
在输出之前显示的文本或 html 代码。
(默认值:为空get_the_tag_list() 和 '标签:' the_tags()) $sep (可选 — 字符串):
用作分隔符的文本。
(默认值: get_the_tag_list() 和 ', ' 表示 the_tags()) $after (可选—字符串):
输出后显示的文本或 html 代码。
(默认:空) 用法<?php// get a plain list of tag links.get_the_tag_list();// display the tags with custom parameters.the_tags( '<div class=mytheme-tags>' . __( 'tags: ', 'translation-domain' ) , ' &middot; ', '</div>' );?>
获取并显示帖子的条款:get_the_term_list() & the_terms()这些模板标签获取并回显为帖子分配的术语列表。
参数两个模板标签都接受五个参数:
$post_id (可选 - 整数):
帖子 id。
(默认:当前帖子) $taxonomy (必需 - 字符串):
显示其术语的分类法。
(默认:空) $before (可选—字符串):
在输出之前显示的文本或 html 代码。
(默认:空) $sep (可选 — 字符串):
分隔符文本。
(默认:', ') $after (可选—字符串):
输出后显示的文本或 html 代码。
(默认:空) 用法<?php// getting current post's terms from the available brands taxonomy.get_the_term_list( $post->id, 'available-brands' );// display current post's terms from the available brands taxonomy with some customization.the_terms( $post->id, 'available-brands', __( 'available brands: ', 'translation-domain' ), ' - ' );?>
显示帖子的分类法:the_taxonomies()此模板标记显示分类法以及与这些分类法关联的术语。
参数此模板标记仅接受一个参数:
$args (可选—数组):
以下参数的数组: 'post'(整数):帖子 id。
(默认:0) 'before'(字符串):在输出之前添加的 html 代码。
(默认:空) 'sep'(字符串):分隔符文本。
(默认:' ') 'after'(字符串):在输出后添加的 html 代码。
(默认:空) 'template'(字符串):用于显示分类术语的模板。
(默认值:'%s: %l。',其中 %s 是分类标签%t 是术语链接列表) 用法<?php$args = array( 'before' => '<div class=taxonomies>', 'sep' => ', ', 'after' => '</div>');the_taxonomies( $args );?>
获取并显示“编辑标签”链接:get_edit_tag_link() & edit_tag_link()这些模板标记返回或回显“编辑此标记”链接,供您在模板中使用。
参数get_edit_tag_link() 接受两个参数:
$tag_id (必需 - 整数):
标签的 id。
(默认:null) > $taxonomy (可选—字符串):
分类法的类型。
(默认:'post_tag')而 edit_tag_link() 接受四个参数:
$link (可选—字符串):
链接显示的文本。
(默认:“编辑此”) $before (可选—字符串):
在输出之前显示的文本或 html 代码。
(默认:空) $after (可选—字符串):
输出后显示的文本或 html 代码。
(默认:空) $tag (必需—对象):
标记对象。
(默认:null)用法<?php// retrieving the current tag's edit tag link.$edit_tag_link = get_edit_tag_link();// retrieving a specific term's edit term link.$edit_tag_link = get_edit_tag_link( 4, 'keyboard-brand' );// displaying the current tag's edit tag link.edit_tag_link( __( 'edit', 'translation-domain' ), '<strong>', '</strong>' );// displaying a specific tag's edit tag link.edit_tag_link( __( 'edit', 'translation-domain' ), '', '', 11 );?>
获取并显示类别列表:wp_list_categories()此模板标记返回或显示任何类型分类法中的类别或术语列表。
参数此模板标记仅接受一个参数:
$args (可选—数组):
以下参数的数组: 'show_option_all'(字符串):如果将其设置为非空值,则显示主页(或设置>阅读中设置的“帖子”页面)的链接。该值将是链接的锚文本。
(默认:空) 'show_option_none'(字符串):如果没有任何类别,则显示文本。
(默认:“无类别”) 'orderby'(字符串):如何对链接进行排序。接受“name”、“id”、“slug”、“count”和“term_group”。
(默认:“name”) 'order'(字符串):是否按升序('asc')或降序('desc')排序项目。
(默认:'asc') 'style'(字符串):显示类别的样式 - 'list' 生成无序列表或 'none' 生成以
s 分隔的链接列表。
(默认:'列表') 'show_count'(整数):在每个类别链接旁边显示帖子计数。
(默认值:0) 'hide_empty'(整数):是否隐藏空类别。
(默认:1) 'use_desc_for_title'(整数):使用描述作为链接的“标题”属性。
(默认:1) 'child_of'(整数):仅显示类别给定 id 的子级。
(默认值:0) 'feed'(字符串):如果设置为任何非空值,类别提要链接将出现在类别链接旁边。该值将是链接的锚文本。
(默认:空) 'feed_type'(字符串):提要类型('rss'、'rss2'、'atom' 或 'rdf')。
(默认:空) 'feed_image'(字符串):覆盖锚文本并显示图像的图像路径。
(默认:空) 'exclude'(字符串):要排除的以逗号分隔的类别 id 列表。
(默认:空) 'exclude_tree' (string): 与“exclude”相同,但如果“hierarchical”参数设置为 1,则必须使用这个
(默认:空) 'current_category'(整数):在合适的情况下添加“current-cat”类。
(默认:0) 'hierarchical'(整数):是否显示具有分层顺序的项目。
(默认:1) 'title_li'(字符串):使用 标签包装输出,并在类别列表之前显示标题。您可能希望将其设置为空字符串并禁用换行。
(默认:“类别”) 'echo'(整数):是否回显输出(1)或返回它(0)。
(默认:1) 'depth'(整数):最大深度。
(默认:0) 'taxonomy'(字符串):要列出的分类法。
(默认:'category') 用法<?php$args = array( // show an all posts link. 'show_option_all' => __( 'all posts', 'translation-domain' ), // order by post count. 'orderby' => 'count', // show post count. 'show_count' => 1, // show feed links. 'feed' => 'feed', // remove title_li. 'title_li' => '');wp_list_categories( $args );?>
获取并显示 html 类别下拉列表:wp_dropdown_categories()此模板标记返回或回显您选择的分类中的类别或术语的下拉菜单 ()。
参数此模板标记仅接受一个参数:
$args (可选—数组):
以下参数的数组: 'show_option_all'(字符串):用于显示所有类别/分类的文本。
(默认:空) 'show_option_none'(字符串):显示不显示类别/分类的文本。
(默认:空) 'option_none_value'(混合):未选择类别/分类时使用的值。
(默认值:-1) 'orderby'(字符串):用于对类别/分类进行排序的列。
(默认:'id') 'order'(字符串):按什么方向排序类别/分类。
(默认:'asc') 'show_count'(布尔值或整数):是否显示类别/分类中有多少帖子。
(默认:0) 'hide_empty'(布尔值或整数):是否隐藏没有附加任何帖子的类别/分类法。
(默认:1) 'child_of'(整数):显示给定 id 的后代的所有类别。
(默认值:0) 'exclude'(字符串):要从列表中排除的以逗号分隔的类别/分类 id 列表。
(默认:空) 'echo'(布尔值或整数):是否显示或检索内容。
(默认:1) 'depth'(整数):最大深度。
(默认:0) 'tab_index'(整数):select 元素的选项卡索引。
(默认值:0) 'name'(字符串):select 元素的 name 属性值。
(默认:'cat') 'id'(字符串):select 元素的 id。
(默认:空) 'class'(字符串):select 元素的 css 类。
(默认:'postform') 'selected'(整数):默认选择的类别/分类id。
(默认:0) 'taxonomy'(字符串):要检索的分类法的名称。
(默认:'category') 用法<?php$args = array( 'show_option_none' => __( 'nothing!', 'translation-domain' ), 'orderby' => 'title', 'show_count' => 1, 'echo' => 0, 'name' => __( 'brands', 'translation-domain' ), 'taxonomy' => __( 'available-brands', 'translation-domain' ));$brands_dropdown = wp_categories_dropdown( $args );?>
获取并显示标签云:wp_tag_cloud()此模板标签返回或显示根据您选择的分类法(默认为标签)生成的术语云。
参数此模板标记仅接受一个参数:
$args (可选—数组):
以下参数的数组: 'smallest'(整数):最小文本大小。
(默认:8) 'largest'(整数):最大文本大小。
(默认:22) 'unit'(字符串):文本大小单位。
(默认:'pt') 'number'(字符串):返回多少个标签
(默认:45) 'format'(字符串):如何返回标签列表 - 'flat' 表示以空格分隔的平面列表,'list' 表示 html 无序列表,'array' 表示 php 数组。
(默认:'平坦') 'separator'(字符串):分隔符文本。
(默认:“\n”) 'orderby'(字符串):如何按('name' 或 'count')对标签进行排序。
(默认:'name') 'order'(字符串):是否按升序('asc')或降序('desc')排序项目。
(默认:'asc') 'include'(数组):要包含的 id 数组。
(默认:空) 'exclude'(数组):要排除的 id 数组。
(默认:空) 'taxonomy'(字符串):从中获取术语的分类法。
(默认:'post_tag') 'link' (string): 'view' 为前端查看, 'edit' 为后端编辑链接。与“post_type”参数一起使用。
(默认:“view”) 'post_type'(字符串):如果'link'参数设置为'edit',则必须将'post_type'设置为帖子类型,以设置“编辑链接”列表中的帖子类型。(默认:空) 'echo' (boolean): 是否回显模板标签。
(默认: true) 用法<?php$args = array( // smallest & largest font sizes. 'smallest' => 10, 'largest' => 32, // get only 20 tags. 'number' => 20, // order by term popularity. 'orderby' => 'count', // custom taxonomy. 'taxonomy' => 'brands', // return output instead of echoing. 'echo' => 0);$tag_cloud = wp_tag_cloud( $args );?>
获取自定义生成的标签云:wp_generate_tag_cloud()此模板标签返回标签云,但这一次,您可以选择自己的标签。
参数此模板标记接受两个参数:
$tags (必需 — 数组):
标签列表的数组。
(默认:null) $args (可选—数组):
以下参数的数组: 'smallest'(整数):最小文本大小。
(默认:8) 'largest'(整数):最大文本大小。
(默认:22) 'unit'(字符串):文本大小单位。
(默认:'pt') 'number'(字符串):返回多少个标签
(默认:0) 'format'(字符串):如何返回标签列表 - 'flat' 表示以空格分隔的平面列表,'list' 表示 html 无序列表,'array' 表示 php 数组。
(默认:'平坦') 'separator'(字符串):分隔符文本。
(默认:“\n”) 'orderby'(字符串):如何按('name' 或 'count')对标签进行排序。
(默认:'name') 'order'(字符串):是否按升序('asc')或降序('desc')排序项目。
(默认:'asc') 'topic_count_text'(字符串):这是 _n_noop() 的 noooped 复数形式,用于生成标签链接工具提示的文本。
(默认:null) 'topic_count_text_callback'(字符串):这是回调函数,它给出带有该标签的帖子的计数,返回标签链接工具提示的文本。
(默认: null) 'topic_count_scale_callback'(字符串):这是与 'smallest' 和 'largest' 参数一起使用的回调函数,用于计算生成标签的字体大小。
(默认:'default_topic_count_scale') 'filter'(整数):如果设置为0,函数将不会通过同名的过滤器。
(默认:1) 用法<?php// get an array of the tags from current post.$tags = get_the_tags( '', ', ', '' );// set arguments.$args = array( 'smallest' => 10, 'largest' => 36, 'orderby' => 'count' );wp_generate_tag_cloud( $tags, $args );?>
结论希望您喜欢第二批模板标签。还有六批要进行,请继续关注更多模板标签!
如果您有任何问题、意见或更正,您可以在评论部分与我们分享您的想法。如果您喜欢这篇文章,请不要忘记与您的朋友分享!
以上就是模板标签:tuts+ 指南继续的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product