函数文档

get_linkobjectsbyname()

💡 云策文档标注

概述

get_linkobjectsbyname() 是一个已弃用的 WordPress 函数,用于根据分类名称获取关联的链接对象数组。开发者应改用 get_bookmarks() 函数。

关键要点

  • 函数已弃用:自 WordPress 2.1.0 起,推荐使用 get_bookmarks() 替代。
  • 功能:根据分类名称 $cat_name 获取链接对象数组,支持排序和数量限制。
  • 参数:$cat_name(可选,默认 'noname')、$orderby(可选,默认 'name')、$limit(可选,默认 -1)。
  • 返回值:返回链接对象数组,若无匹配分类则返回所有链接。

代码示例

$links = get_linkobjectsbyname('fred');
foreach ($links as $link) {
    echo '<li>' . $link->link_name . '</li>';
}

注意事项

  • 此函数已标记为弃用,使用时会触发 _deprecated_function() 警告。
  • 内部调用 get_linkobjects() 和 get_term_by() 实现功能。

📄 原文内容

Gets an array of link objects associated with category $cat_name.

Description

$links = get_linkobjectsbyname( ‘fred’ ); foreach ( $links as $link ) { echo ‘

  • ‘ . $link->link_name . ‘
  • ‘; }

    See also

    Parameters

    $cat_namestringoptional
    The category name to use. If no match is found, uses all.
    Default 'noname'.
    $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:-1

    Return

    array

    Source

    function get_linkobjectsbyname($cat_name = "noname" , $orderby = 'name', $limit = -1) {
    	_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;
    
    	return get_linkobjects($cat_id, $orderby, $limit);
    }
    

    Changelog

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