函数文档

get_linkobjects()

💡 云策文档标注

概述

get_linkobjects() 是一个已弃用的 WordPress 函数,用于获取与指定分类关联的链接对象数组。自 2.1.0 版本起,建议使用 get_bookmarks() 替代。

关键要点

  • 函数已弃用:自 WordPress 2.1.0 起,应使用 get_bookmarks() 替代。
  • 功能:返回链接对象数组,包含 link_id、link_url、link_name 等字段。
  • 参数:$category(分类 ID,可选,默认 0)、$orderby(排序方式,可选,默认 'name')、$limit(限制条目数,可选,默认 0)。
  • 返回值:链接对象数组,可直接遍历使用。

代码示例

$links = get_linkobjects(1);
if ($links) {
    foreach ($links as $link) {
        echo ''.$link->link_name.''.$link->link_description.'';
    }
}

注意事项

  • 此函数已弃用,新代码应避免使用,改用 get_bookmarks()。
  • 参数 $orderby 支持 'id'、'name'、'url'、'description'、'rating'、'owner' 等值,前缀下划线可反转顺序,'rand' 用于随机排序。
  • 相关函数:get_bookmarks()(替代函数)、_deprecated_function()(标记弃用)、get_linkobjectsbyname()(基于分类名的类似弃用函数)。

📄 原文内容

Gets an array of link objects associated with category n.

Description

Usage:

$links = get_linkobjects(1);
if ($links) {
    foreach ($links as $link) {
        echo '<li>'.$link->link_name.'<br />'.$link->link_description.'</li>';
    }
}

Fields are:

  • link_id
  • link_url
  • link_name
  • link_image
  • link_target
  • link_category
  • link_description
  • link_visible
  • link_owner
  • link_rating
  • link_updated
  • link_rel
  • link_notes

See also

Parameters

$categoryintoptional
The category to use. If no category supplied, uses all.
Default 0.
$orderbystringoptional
The order to output the links. E.g. 'id', 'name', 'url', 'description', 'rating', or 'owner'. Default 'name'.
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.
$limitintoptional
Limit to X entries. If not specified, all entries are shown.
Default 0.

Return

array

Source

function get_linkobjects($category = 0, $orderby = 'name', $limit = 0) {
	_deprecated_function( __FUNCTION__, '2.1.0', 'get_bookmarks()' );

	$links = get_bookmarks( array( 'category' => $category, 'orderby' => $orderby, 'limit' => $limit ) ) ;

	$links_array = array();
	foreach ($links as $link)
		$links_array[] = $link;

	return $links_array;
}

Changelog

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