在本系列的第二部分中,我们介绍了第一批 WordPress 模板标签。在第三部分中,我们将介绍第二批近 200 个模板标签。在整个教程中,我们将看到有关分类法和术语的模板标签。
此模板标记返回类别的描述。
此模板标记仅接受一个参数:
类别ID。
(默认:查询的类别) >
<?php $cat_desc = get_category_description( 15 ); ?>
此模板标记返回标记的描述。
此模板标记仅接受一个参数:
标签的 ID。
(默认:当前标签)
<?php // Display the description of current tag. echo tag_description(); // Get the description of a specific tag. $special_tag_desc = tag_description( 42 ); ?>
此模板标记仅返回术语的描述。
此模板标记接受两个参数:
术语的 ID。
(默认:当前术语)
术语的分类。
(默认:'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' ); ?>
此模板标记返回并显示类别的标题,以便在页面标题中使用。
此模板标记接受两个参数:
标题前缀。
(默认:空)
是否 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 ); ?>
此模板标记返回并显示标记的标题,以便在页面标题中使用。
此模板标记接受两个参数:
标题前缀。
(默认:空)
是否 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 ); ?>
此模板标记返回并显示在页面标题中使用的术语标题。
此模板标记接受两个参数:
标题前缀。
(默认:空)
是否 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 ); ?>
这些模板标签获取并输出分配给帖子的类别。
两个模板标签都接受三个参数:
分隔符文本。
(默认:空—如果此参数为空,则函数将返回并显示类别的无序列表)
如何显示父类别(“多个”、“单个”或空)。
(默认:空)
帖子 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' ); ?>
这些模板标签使分配给帖子的类别准备好供提要并返回或显示它。
两个模板标签只接受一个参数:
提要类型。
(默认:默认提要类型)
<?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' ); ?>
这些模板标签返回或显示您帖子的标签。
两个模板标签都接受三个参数:
在输出之前显示的文本或 HTML 代码。
(默认值:为空get_the_tag_list() 和 '标签:' the_tags())
用作分隔符的文本。
(默认值: get_the_tag_list() 和 ', ' 表示 the_tags())
输出后显示的文本或 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' ) , ' · ', '</div>' ); ?>
这些模板标签获取并回显为帖子分配的术语列表。
两个模板标签都接受五个参数:
帖子 ID。
(默认:当前帖子)
显示其术语的分类法。
(默认:空)
在输出之前显示的文本或 HTML 代码。
(默认:空)
分隔符文本。
(默认:', ')
输出后显示的文本或 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' ), ' - ' ); ?>
此模板标记显示分类法以及与这些分类法关联的术语。
此模板标记仅接受一个参数:
以下参数的数组:
(默认:0)
(默认:空)
(默认:' ')
(默认:空)
(默认值:'%s: %l。',其中 %s 是分类标签%t 是术语链接列表)
<?php $args = array( 'before' => '<div class="taxonomies">', 'sep' => ', ', 'after' => '</div>' ); the_taxonomies( $args ); ?>
这些模板标记返回或回显“编辑此标记”链接,供您在模板中使用。
get_edit_tag_link() 接受两个参数:
标签的 ID。
(默认:NULL) >
分类法的类型。
(默认:'post_tag')
而 edit_tag_link() 接受四个参数:
链接显示的文本。
(默认:“编辑此”)
在输出之前显示的文本或 HTML 代码。
(默认:空)
输出后显示的文本或 HTML 代码。
(默认:空)
标记对象。
(默认: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 ); ?>
此模板标记返回或显示任何类型分类法中的类别或术语列表。
此模板标记仅接受一个参数:
以下参数的数组:
(默认:空)
(默认:“无类别”)
(默认:“name”)
(默认:'ASC')
(默认:'列表')
(默认值:0)
(默认:1)
(默认:1)
(默认值:0)
(默认:空)
(默认:空)
(默认:空)
(默认:空)
(默认:空)
(默认:0)
(默认:1)
(默认:“类别”)
(默认:1)
(默认:0)
(默认:'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 ); ?>
此模板标记返回或回显您选择的分类中的类别或术语的下拉菜单 (
此模板标记仅接受一个参数:
以下参数的数组:
(默认:空)
(默认:空)
(默认值:-1)
(默认:'ID')
(默认:'ASC')
(默认:0)
(默认:1)
(默认值:0)
(默认:空)
(默认:1)
(默认:0)
(默认值:0)
(默认:'cat')
(默认:空)
(默认:'postform')
(默认:0)
(默认:'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 ); ?>
此模板标签返回或显示根据您选择的分类法(默认为标签)生成的术语云。
此模板标记仅接受一个参数:
以下参数的数组:
(默认:8)
(默认:22)
(默认:'pt')
(默认:45)
(默认:'平坦')
(默认:“\n”)
(默认:'name')
(默认:'ASC')
(默认:空)
(默认:空)
(默认:'post_tag')
(默认:“view”)
(默认:空)
(默认: 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 ); ?>
此模板标签返回标签云,但这一次,您可以选择自己的标签。
此模板标记接受两个参数:
标签列表的数组。
(默认:NULL)
以下参数的数组:
(默认:8)
(默认:22)
(默认:'pt')
(默认:0)
(默认:'平坦')
(默认:“\n”)
(默认:'name')
(默认:'ASC')
(默认:NULL) EM>
(默认: NULL)
(默认:'default_topic_count_scale')
(默认: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+ 指南继续的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号