函数文档

link_categories_meta_box()

💡 云策文档标注

概述

link_categories_meta_box() 函数用于在 WordPress 后台显示链接分类的元框表单字段,主要用于编辑链接时管理其分类。它根据当前链接对象参数调用 wp_link_category_checklist() 来输出分类选择列表。

关键要点

  • 函数功能:显示链接分类的表单字段,作为元框的一部分
  • 参数:接受一个必需的 $link 参数,表示当前链接对象
  • 核心调用:根据链接 ID 是否存在,调用 wp_link_category_checklist() 函数来生成分类复选框列表
  • 相关函数:涉及 wp_link_category_checklist()、wp_popular_terms_checklist()、_ex()、esc_attr_e()、wp_nonce_field() 和 _e() 等辅助函数
  • 版本历史:自 WordPress 2.6.0 版本引入

代码示例

function link_categories_meta_box( $link ) {
    if ( isset( $link->link_id ) ) {
        wp_link_category_checklist( $link->link_id );
    } else {
        wp_link_category_checklist();
    }
}

注意事项

  • 该函数主要用于后台链接编辑界面,开发者不应直接在前端调用
  • 参数 $link 必须是一个链接对象,否则可能导致错误
  • 函数内部使用了非ce字段(wp_nonce_field())以确保表单安全性

📄 原文内容

Displays link categories form fields.

Parameters

$linkobjectrequired
Current link object.

Source

function link_categories_meta_box( $link ) {
?>
<div id="taxonomy-linkcategory" class="categorydiv">
<ul id="category-tabs" class="category-tabs">
<li class="tabs"><a href="#categories-all"></a></li>
<li class="hide-if-no-js"><a href="#categories-pop"></a></li>
</ul>

<div id="categories-all" class="tabs-panel">
<ul id="categorychecklist" data-wp-lists="list:category" class="categorychecklist form-no-clear">
link_id ) ) {
wp_link_category_checklist( $link->link_id );
} else {
wp_link_category_checklist();
}
?>
</ul>
</div>

<div id="categories-pop" class="tabs-panel" style="display: none;">
<ul id="categorychecklist-pop" class="categorychecklist form-no-clear">

</ul>
</div>

<div id="category-adder" class="wp-hidden-children">
<a id="category-add-toggle" href="#category-add" class="taxonomy-add-new"></a>
<p id="link-category-add" class="wp-hidden-child">
<label class="screen-reader-text" for="newcat">

</label>
<input type="text" name="newcat" id="newcat" class="form-required form-input-tip" value="<?php esc_attr_e( 'New category name' ); ?>" aria-required="true" />
<input type="button" id="link-category-add-submit" data-wp-lists="add:categorychecklist:link-category-add" class="button" value="<?php esc_attr_e( 'Add' ); ?>" />

<span id="category-ajax-response"></span>
</p>
</div>
</div>
</pre><p class="wporg-dot-link-list"><a href="https://developer.wordpress.org/reference/files/wp-admin/includes/meta-boxes.php/">View all references</a> <a href="https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/meta-boxes.php#L1176">View on Trac</a> <a href="https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/meta-boxes.php#L1176-L1219">View on GitHub</a></p></section>

<section class="wp-block-wporg-code-reference-related" data-nosnippet="true"><h2 id="related" class="is-toc-heading wp-block-heading has-heading-5-font-size" tabindex="-1" ><a href="#related">Related</a></h2> <section style="margin-top:var(--wp--preset--spacing--20)" class="wp-block-wporg-code-table" id="uses"><figure class="wp-block-table "><table><thead><tr><th scope="col">Uses</th><th scope="col">Description</th></tr></thead><tbody><tr class=""><td><a href="https://developer.wordpress.org/reference/functions/wp_link_category_checklist/">wp_link_category_checklist()</a><code>wp-admin/includes/template.php

Outputs a link category checklist element.

wp_popular_terms_checklist()wp-admin/includes/template.php

Retrieves a list of the most popular terms from the specified taxonomy.

_ex()wp-includes/l10n.php

Displays translated string with gettext context.

esc_attr_e()wp-includes/l10n.php

Displays translated text that has been escaped for safe use in an attribute.

wp_nonce_field()wp-includes/functions.php

Retrieves or display nonce hidden field for forms.

_e()wp-includes/l10n.php

Displays translated text.

Show 1 moreShow less

Changelog

Version Description
2.6.0 Introduced.