Maison  >  Article  >  développement back-end  >  Balises du modèle : Tutorial Tuts+ (suite)

Balises du modèle : Tutorial Tuts+ (suite)

PHPz
PHPzoriginal
2023-08-31 18:17:051009parcourir

模板标签:Tuts+ 指南继续

Dans la deuxième partie de cette série, nous avons présenté les premières balises de modèles WordPress. Dans la troisième partie, nous présenterons le deuxième lot de près de 200 balises de modèle. Tout au long du didacticiel, nous verrons des balises de modèle pour les taxonomies et les termes.

Obtenir une description d'une catégorie : category_description()

Cette balise de modèle renvoie la description de la catégorie.

Paramètres

Cette balise de modèle n'accepte qu'un seul paramètre :

    <li> $category_ID (facultatif — entier)  :

    ID de catégorie.

    (par défaut : catégorie de requête) >

Utilisation

<?php

$cat_desc = get_category_description( 15 );

?>

Obtenez la description du tag : tag_description()

Cette balise de modèle renvoie une description de la balise.

Paramètres

Cette balise de modèle n'accepte qu'un seul paramètre :

    <li> $tag_ID (facultatif - entier)  :

    L'ID du tag.

    (par défaut : étiquette actuelle)

Utilisation

<?php

// Display the description of current tag.
echo tag_description();

// Get the description of a specific tag.
$special_tag_desc = tag_description( 42 );

?>

Obtenir une description d'un terme : term_description()

Cette balise de modèle renvoie uniquement la description du terme.

Paramètres

Cette balise de modèle accepte deux paramètres :

    <li> $term_ID (facultatif - entier)  :

    L'identifiant du terme.

    (par défaut : mandat en cours)

    <li> $taxonomy (facultatif — chaîne)  :

    classification du terme.

    (Par défaut : 'post_tag') >

Utilisation

<?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' );

?>

Récupérez et affichez le titre de la page de l'archive de la catégorie : single_cat_title()

Cette balise de modèle renvoie et affiche le titre de la catégorie à utiliser dans les titres de page.

Paramètres

Cette balise de modèle accepte deux paramètres :

    <li> $prefix (facultatif — chaîne)  :

    Préfixe du titre.

    (par défaut : vide)

    <li> $echo $echo (可选 - 布尔值)

    是否 echo (TRUE) 或返回 (FALSE) 标签。

    (默认:TRUE (facultatif - booléen)  :

S'il faut faire écho (TRUE) ou renvoyer (FALSE) aux balises.

(par défaut : VRAI)single_tag_title()

Utilisation

<?php

// Display the category title with a prefix.
single_cat_title( 'Category: ' );

// Get the category title.
$cat_title = single_cat_title( '', false );

?>

Récupérez et affichez le titre de la page de l'archive de tags :

    Cette balise de modèle renvoie et affiche le titre de la balise à utiliser dans les titres de page. <li> $prefixParamètres Cette balise de modèle accepte deux paramètres :

    (facultatif — chaîne)  :

    <li>Préfixe du titre. $echo (可选 - 布尔值)

    是否 echo (TRUE) 或返回 (FALSE) 标签。

    (默认:TRUE

    (par défaut : vide)

$echo

(facultatif - booléen) single_term_title() :

S'il faut faire écho (TRUE) ou renvoyer (FALSE) aux balises.

(par défaut : VRAI)

    <li>Utilisation$prefix
    <?php
    
    // Display the tag title with a prefix.
    single_tag_title( 'Tag Archive: ' );
    
    // Get the tag title.
    $tag_title = single_tag_title( '', false );
    
    ?>
    
    Obtenez et affichez le titre de la page de l'archive de termes :

    Cette balise de modèle renvoie et affiche le terme titre utilisé dans le titre de la page.

    Paramètres Cette balise de modèle accepte deux paramètres :

    <li> $echo (可选 - 布尔值)

    是否 echo (TRUE) 或返回 (FALSE) 标签。

    (默认:TRUE

    (facultatif — chaîne)
 :

Préfixe du titre.

get_the_category_list() & the_category()

(par défaut : vide)

$echo

(facultatif - booléen)

 :

    S'il faut faire écho (TRUE) ou renvoyer (FALSE) aux balises. <li> $separator(par défaut : VRAI)

    Utilisation

    <?php
    
    // Display the term title with a prefix.
    single_term_title( 'Term Archive: ' );
    
    // Get the term title.
    $term_title = single_term_title( '', false );
    
    ?>
    
    Récupérez et affichez la catégorie du post :

    <li>Ces balises de modèle obtiennent et affichent la catégorie attribuée à la publication. $parents Paramètres Les deux balises de modèle acceptent trois paramètres :

    (facultatif — chaîne)

     : <li> $post_ID texte délimiteur. (par défaut : vide - si ce paramètre est vide, la fonction retournera et affichera une liste non ordonnée de catégories)

    (facultatif - chaîne)

     :

Comment afficher la catégorie parent ("multiple", "unique" ou vide).

get_the_category_rss() & the_category_rss()(par défaut : vide)

(facultatif - entier)

 :

    Post ID. <li> $feed_type(par défaut : message actuel)

    Utilisation

    <?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' );
    
    ?>
    
    Obtenez et affichez les catégories de publications du fil :

Ces balises de modèle préparent la catégorie attribuée à la publication pour l'alimenter et la renvoyer ou l'afficher.

Paramètres

get_the_tag_list() & the_tags()Deux balises de modèle n'acceptent qu'un seul paramètre :

(facultatif - chaîne)

 :

    type de flux. <li> $before (par défaut : type de flux par défaut)

    Utilisation🎜
    <?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' );
    
    ?>
    
    🎜Récupérez et affichez les tags de la publication : 🎜 🎜 🎜Ces balises de modèle renvoient ou affichent des balises pour vos publications. 🎜 🎜Paramètres🎜 🎜Les deux balises de modèle acceptent trois paramètres : 🎜 🎜 🎜 🎜 🎜 (facultatif — chaîne) 🎜 : 🎜🎜Texte ou code HTML à afficher avant la sortie. 🎜

    (默认值:为空get_the_tag_list() 和 '标签:' the_tags())

    <li> $sep (可选 — 字符串)

    用作分隔符的文本。

    (默认值: get_the_tag_list() 和 ', ' 表示 the_tags())

    <li> $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()

这些模板标签获取并回显为帖子分配的术语列表。

参数

两个模板标签都接受五个参数:

    <li> $post_ID (可选 - 整数)

    帖子 ID。

    (默认:当前帖子)

    <li> $taxonomy (必需 - 字符串)

    显示其术语的分类法。

    (默认:空)

    <li> $before (可选—字符串)

    在输出之前显示的文本或 HTML 代码。

    (默认:空)

    <li> $sep (可选 — 字符串)

    分隔符文本。

    (默认:', ')

    <li> $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()

此模板标记显示分类法以及与这些分类法关联的术语。

参数

此模板标记仅接受一个参数:

    <li> $args (可选—数组)

    以下参数的数组:

      <li> 'post'(整数):帖子 ID。

      (默认:0)

      <li> 'before'(字符串):在输出之前添加的 HTML 代码。

      (默认:空)

      <li> 'sep'(字符串):分隔符文本。

      (默认:' ')

      <li> 'after'(字符串):在输出后添加的 HTML 代码。

      (默认:空)

      <li> '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() 接受两个参数:

    <li> $tag_ID (必需 - 整数)

    标签的 ID。

    (默认:NULL >

    <li> $taxonomy (可选—字符串)

    分类法的类型。

    (默认:'post_tag')

edit_tag_link() 接受四个参数:

    <li> $link (可选—字符串)

    链接显示的文本。

    (默认:“编辑此”)

    <li> $before (可选—字符串)

    在输出之前显示的文本或 HTML 代码。

    (默认:空)

    <li> $after (可选—字符串)

    输出后显示的文本或 HTML 代码。

    (默认:空)

    <li> $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()

此模板标记返回或显示任何类型分类法中的类别或术语列表。

参数

此模板标记仅接受一个参数:

    <li> $args (可选—数组)

    以下参数的数组:

      <li> 'show_option_all'(字符串):如果将其设置为非空值,则显示主页(或设置>阅读中设置的“帖子”页面)的链接。该值将是链接的锚文本。

      (默认:空)

      <li> 'show_option_none'(字符串):如果没有任何类别,则显示文本。

      (默认:“无类别”)

      <li> 'orderby'(字符串):如何对链接进行排序。接受“name”、“ID”、“slug”、“count”和“term_group”。

      (默认:“name”)

      <li> 'order'(字符串):是否按升序('ASC')或降序('DESC')排序项目。

      (默认:'ASC')

      <li> 'style'(字符串):显示类别的样式 - 'list' 生成无序列表或 'none' 生成以 <br>s 分隔的链接列表。

      (默认:'列表')

      <li> 'show_count'(整数):在每个类别链接旁边显示帖子计数。

      (默认值:0)

      <li> 'hide_empty'(整数):是否隐藏空类别。

      (默认:1)

      <li> 'use_desc_for_title'(整数):使用描述作为链接的“标题”属性。

      (默认:1)

      <li> 'child_of'(整数):仅显示类别给定 ID 的子级。

      (默认值:0)

      <li> 'feed'(字符串):如果设置为任何非空值,类别提要链接将出现在类别链接旁边。该值将是链接的锚文本。

      (默认:空)

      <li> 'feed_type'(字符串):提要类型('rss'、'rss2'、'atom' 或 'rdf')。

      (默认:空)

      <li> 'feed_image'(字符串):覆盖锚文本并显示图像的图像路径。

      (默认:空)

      <li> 'exclude'(字符串):要排除的以逗号分隔的类别 ID 列表。

      (默认:空)

      <li> 'exclude_tree' (string): 与“exclude”相同,但如果“hierarchical”参数设置为 1,则必须使用这个

      (默认:空)

      <li> 'current_category'(整数):在合适的情况下添加“current-cat”类。

      (默认:0)

      <li> 'hierarchical'(整数):是否显示具有分层顺序的项目。

      (默认:1)

      <li> 'title_li'(字符串):使用 <li> 标签包装输出,并在类别列表之前显示标题。您可能希望将其设置为空字符串并禁用换行。

      (默认:“类别”)

      <li> 'echo'(整数):是否回显输出(1)或返回它(0)。

      (默认:1)

      <li> 'depth'(整数):最大深度。

      (默认:0)

      <li> '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()

此模板标记返回或回显您选择的分类中的类别或术语的下拉菜单 (<select></select>)。

参数

此模板标记仅接受一个参数:

    <li> $args (可选—数组)

    以下参数的数组:

      <li> 'show_option_all'(字符串):用于显示所有类别/分类的文本。

      (默认:空)

      <li> 'show_option_none'(字符串):显示不显示类别/分类的文本。

      (默认:空)

      <li> 'option_none_value'(混合):未选择类别/分类时使用的值。

      (默认值:-1)

      <li> 'orderby'(字符串):用于对类别/分类进行排序的列。

      (默认:'ID')

      <li> 'order'(字符串):按什么方向排序类别/分类。

      (默认:'ASC')

      <li> 'show_count'(布尔值或整数):是否显示类别/分类中有多少帖子。

      (默认:0)

      <li> 'hide_empty'(布尔值或整数):是否隐藏没有附加任何帖子的类别/分类法。

      (默认:1)

      <li> 'child_of'(整数):显示给定 ID 的后代的所有类别。

      (默认值:0)

      <li> 'exclude'(字符串):要从列表中排除的以逗号分隔的类别/分类 ID 列表。

      (默认:空)

      <li> 'echo'(布尔值或整数):是否显示或检索内容。

      (默认:1)

      <li> 'depth'(整数):最大深度。

      (默认:0)

      <li> 'tab_index'(整数):SELECT 元素的选项卡索引。

      (默认值:0)

      <li> 'name'(字符串):SELECT 元素的 NAME 属性值。

      (默认:'cat')

      <li> 'id'(字符串):SELECT 元素的 ID。

      (默认:空)

      <li> 'class'(字符串):SELECT 元素的 CSS 类。

      (默认:'postform')

      <li> 'selected'(整数):默认选择的类别/分类ID。

      (默认:0)

      <li> '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()

此模板标签返回或显示根据您选择的分类法(默认为标签)生成的术语云。

参数

此模板标记仅接受一个参数:

    <li> $args (可选—数组)

    以下参数的数组:

      <li> 'smallest'(整数):最小文本大小。

      (默认:8)

      <li> 'largest'(整数):最大文本大小。

      (默认:22)

      <li> 'unit'(字符串):文本大小单位。

      (默认:'pt')

      <li> 'number'(字符串):返回多少个标签

      (默认:45)

      <li> 'format'(字符串):如何返回标签列表 - 'flat' 表示以空格分隔的平面列表,'list' 表示 HTML 无序列表,'array' 表示 PHP 数组。

      (默认:'平坦')

      <li> 'separator'(字符串):分隔符文本。

      (默认:“\n”)

      <li> 'orderby'(字符串):如何按('name' 或 'count')对标签进行排序。

      (默认:'name')

      <li> 'order'(字符串):是否按升序('ASC')或降序('DESC')排序项目。

      (默认:'ASC')

      <li> 'include'(数组):要包含的 ID 数组。

      (默认:空)

      <li> 'exclude'(数组):要排除的 ID 数组。

      (默认:空)

      <li> 'taxonomy'(字符串):从中获取术语的分类法。

      (默认:'post_tag')

      <li> 'link' (string): 'view' 为前端查看, 'edit' 为后端编辑链接。与“post_type”参数一起使用。

      (默认:“view”)

      <li> 'post_type'(字符串):如果'link'参数设置为'edit',则必须将'post_type'设置为帖子类型,以设置“编辑链接”列表中的帖子类型。

      (默认:空)

      <li> '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()

此模板标签返回标签云,但这一次,您可以选择自己的标签。

参数

此模板标记接受两个参数:

    <li> $tags (必需 — 数组)

    标签列表的数组。

    (默认:NULL

    <li> $args (可选—数组)

    以下参数的数组:

      <li> 'smallest'(整数):最小文本大小。

      (默认:8)

      <li> 'largest'(整数):最大文本大小。

      (默认:22)

      <li> 'unit'(字符串):文本大小单位。

      (默认:'pt')

      <li> 'number'(字符串):返回多少个标签

      (默认:0)

      <li> 'format'(字符串):如何返回标签列表 - 'flat' 表示以空格分隔的平面列表,'list' 表示 HTML 无序列表,'array' 表示 PHP 数组。

      (默认:'平坦')

      <li> 'separator'(字符串):分隔符文本。

      (默认:“\n”)

      <li> 'orderby'(字符串):如何按('name' 或 'count')对标签进行排序。

      (默认:'name')

      <li> 'order'(字符串):是否按升序('ASC')或降序('DESC')排序项目。

      (默认:'ASC')

      <li> 'topic_count_text'(字符串):这是 _n_noop() 的 noooped 复数形式,用于生成标签链接工具提示的文本。

      (默认:NULL) EM>

      <li> 'topic_count_text_callback'(字符串):这是回调函数,它给出带有该标签的帖子的计数,返回标签链接工具提示的文本。

      (默认: NULL)

      <li> 'topic_count_scale_callback'(字符串):这是与 'smallest''largest' 参数一起使用的回调函数,用于计算生成标签的字体大小。

      (默认:'default_topic_count_scale')

      <li> '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 );

?>

结论

希望您喜欢第二批模板标签。还有六批要进行,请继续关注更多模板标签!

如果您有任何问题、意见或更正,您可以在评论部分与我们分享您的想法。如果您喜欢这篇文章,请不要忘记与您的朋友分享!

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn