函数文档

get_linksbyname()

💡 云策文档标注

概述

get_linksbyname() 是一个已弃用的 WordPress 函数,用于根据分类名称获取关联的链接。自 2.1.0 版本起,建议使用 get_bookmarks() 替代。

关键要点

  • 函数已弃用:自 WordPress 2.1.0 起,应改用 get_bookmarks() 函数。
  • 功能:根据指定的分类名称 $cat_name 获取链接,支持多种输出控制参数。
  • 参数:包括 $cat_name(分类名称)、$before(链接前 HTML)、$after(链接后 HTML)、$between(链接与描述间 HTML)、$show_images(是否显示图片)、$orderby(排序方式)、$show_description(是否显示描述)、$show_rating(是否显示评分)、$limit(限制条目数)、$show_updated(是否显示更新时间)。
  • 内部实现:通过 get_term_by() 获取分类 ID,然后调用 get_links() 函数处理。

代码示例

function get_linksbyname($cat_name = "noname", $before = '', $after = '', $between = " ", $show_images = true, $orderby = 'id',
						$show_description = true, $show_rating = false,
						$limit = -1, $show_updated = 0) {
	_deprecated_function( __FUNCTION__, '2.1.0', 'get_bookmarks()' );

	$cat_id = -1;
	$cat = get_term_by('name', $cat_name, 'link_category');
	if ( $cat )
		$cat_id = $cat->term_id;

	get_links($cat_id, $before, $after, $between, $show_images, $orderby, $show_description, $show_rating, $limit, $show_updated);
}

注意事项

  • 此函数已弃用,新代码中应避免使用,改用 get_bookmarks() 以确保兼容性。
  • 参数 $cat_name 默认值为 'noname',如果未找到匹配分类,则使用所有链接。
  • 排序参数 $orderby 支持 'id'、'name'、'url'、'description'、'rating'、'owner' 等值,以 '_' 开头可反转顺序,'rand' 表示随机排序。
  • 函数内部调用 _deprecated_function() 来标记弃用状态。

📄 原文内容

Gets the links associated with category $cat_name.

Description

See also

Parameters

$cat_namestringoptional
The category name to use. If no match is found, uses all.
Default 'noname'.
$beforestringoptional
The HTML to output before the link. Default empty.
$afterstringoptional
The HTML to output after the link. Default <br />.
$betweenstringoptional
The HTML to output between the link/image and its description.
Not used if no image or $show_images is true. Default ‘ ‘.
$show_imagesbooloptional
Whether to show images (if defined).

Default:true

$orderbystringoptional
The order to output the links. E.g. 'id', 'name', 'url', 'description', 'rating', or 'owner'. Default 'id'.
If you start the name with an underscore, the order will be reversed.
Specifying 'rand' as the order will return links in a random order.
$show_descriptionbooloptional
Whether to show the description if show_images=false/not defined.

Default:true

$show_ratingbooloptional
Show rating stars/chars.

Default:false

$limitintoptional
Limit to X entries. If not specified, all entries are shown.

Default:-1

$show_updatedintoptional
Whether to show last updated timestamp. Default 0.

Source

function get_linksbyname($cat_name = "noname", $before = '', $after = '<br />', $between = " ", $show_images = true, $orderby = 'id',
						$show_description = true, $show_rating = false,
						$limit = -1, $show_updated = 0) {
	_deprecated_function( __FUNCTION__, '2.1.0', 'get_bookmarks()' );

	$cat_id = -1;
	$cat = get_term_by('name', $cat_name, 'link_category');
	if ( $cat )
		$cat_id = $cat->term_id;

	get_links($cat_id, $before, $after, $between, $show_images, $orderby, $show_description, $show_rating, $limit, $show_updated);
}

Changelog

Version Description
2.1.0 Deprecated. Use get_bookmarks()
0.71 Introduced.