wp_get_linksbyname()
云策文档标注
概述
wp_get_linksbyname() 是一个已弃用的 WordPress 函数,用于获取指定分类下的链接。它已被 wp_list_bookmarks() 替代,内部通过参数处理调用 wp_list_bookmarks() 实现功能。
关键要点
- 函数 wp_get_linksbyname() 从 WordPress 2.1.0 版本起已弃用,建议使用 wp_list_bookmarks()。
- 接受两个参数:$category(必需,指定分类名称)和 $args(可选,用于自定义输出的参数数组)。
- 内部使用 wp_parse_args() 合并默认参数,并调用 wp_list_bookmarks() 返回链接列表。
- 默认参数包括 categorize、show_description 等,用于控制链接显示的格式和内容。
代码示例
function wp_get_linksbyname($category, $args = '') {
_deprecated_function(__FUNCTION__, '2.1.0', 'wp_list_bookmarks()');
$defaults = array(
'after' => '',
'before' => '',
'categorize' => 0,
'category_after' => '',
'category_before' => '',
'category_name' => $category,
'show_description' => 1,
'title_li' => '',
);
$parsed_args = wp_parse_args( $args, $defaults );
return wp_list_bookmarks($parsed_args);
}注意事项
- 由于该函数已弃用,在新开发中应避免使用,转而使用 wp_list_bookmarks() 以确保兼容性和维护性。
- 调用此函数会触发 _deprecated_function() 警告,提醒开发者更新代码。
原文内容
Gets the links associated with the named category.
Description
See also
Parameters
$categorystringrequired-
The category to use.
$argsstringrequired
Source
function wp_get_linksbyname($category, $args = '') {
_deprecated_function(__FUNCTION__, '2.1.0', 'wp_list_bookmarks()');
$defaults = array(
'after' => '<br />',
'before' => '',
'categorize' => 0,
'category_after' => '',
'category_before' => '',
'category_name' => $category,
'show_description' => 1,
'title_li' => '',
);
$parsed_args = wp_parse_args( $args, $defaults );
return wp_list_bookmarks($parsed_args);
}
Changelog
| Version | Description |
|---|---|
| 2.1.0 | Deprecated. Use wp_list_bookmarks() |
| 1.0.1 | Introduced. |