返回介绍

get_bookmark()

发布于 2017-09-10 22:54:39 字数 4301 浏览 1010 评论 0 收藏 0

get_bookmark( int|stdClass $bookmark,  string $output = OBJECT,  string $filter = 'raw' )

Retrieve Bookmark data


description


参数

$bookmark

(int|stdClass) (Required)

$output

(string) (Optional) The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to an stdClass object, an associative array, or a numeric array, respectively.

Default value: OBJECT

$filter

(string) (Optional)

Default value: 'raw'


返回值

(array|object|null) Type returned depends on $output value.


源代码

File: wp-includes/bookmark.php

function get_bookmark($bookmark, $output = OBJECT, $filter = 'raw') {
	global $wpdb;

	if ( empty($bookmark) ) {
		if ( isset($GLOBALS['link']) )
			$_bookmark = & $GLOBALS['link'];
		else
			$_bookmark = null;
	} elseif ( is_object($bookmark) ) {
		wp_cache_add($bookmark->link_id, $bookmark, 'bookmark');
		$_bookmark = $bookmark;
	} else {
		if ( isset($GLOBALS['link']) && ($GLOBALS['link']->link_id == $bookmark) ) {
			$_bookmark = & $GLOBALS['link'];
		} elseif ( ! $_bookmark = wp_cache_get($bookmark, 'bookmark') ) {
			$_bookmark = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->links WHERE link_id = %d LIMIT 1", $bookmark));
			if ( $_bookmark ) {
				$_bookmark->link_category = array_unique( wp_get_object_terms( $_bookmark->link_id, 'link_category', array( 'fields' => 'ids' ) ) );
				wp_cache_add( $_bookmark->link_id, $_bookmark, 'bookmark' );
			}
		}
	}

	if ( ! $_bookmark )
		return $_bookmark;

	$_bookmark = sanitize_bookmark($_bookmark, $filter);

	if ( $output == OBJECT ) {
		return $_bookmark;
	} elseif ( $output == ARRAY_A ) {
		return get_object_vars($_bookmark);
	} elseif ( $output == ARRAY_N ) {
		return array_values(get_object_vars($_bookmark));
	} else {
		return $_bookmark;
	}
}

更新日志

Versiondescription
2.1.0Introduced.

相关函数

Uses

  • wp-includes/cache.php: wp_cache_add()
  • wp-includes/cache.php: wp_cache_get()
  • wp-includes/taxonomy.php: wp_get_object_terms()
  • wp-includes/bookmark.php: sanitize_bookmark()
  • wp-includes/wp-db.php: wpdb::get_row()
  • wp-includes/wp-db.php: wpdb::prepare()
  • Show 1 more use Hide more uses

Used By

  • wp-admin/includes/ajax-actions.php: wp_ajax_delete_link()
  • wp-admin/includes/bookmark.php: get_link_to_edit()
  • wp-admin/includes/bookmark.php: wp_update_link()
  • wp-includes/deprecated.php: get_link()
  • wp-includes/link-template.php: get_edit_bookmark_link()
  • wp-includes/link-template.php: edit_bookmark_link()
  • wp-includes/bookmark.php: get_bookmark_field()
  • Show 2 more used by Hide more used by

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Codex

    Display Bookmark Name

    
    <?php 
    $bookmark = get_bookmark(5);
    echo $bookmark->link_name; 
    ?>
    

    or:

    
    <?php echo get_bookmark(5)->link_name; ?>
    
  2. Display Bookmark as a Link

    
    <?php  
    $bookmark = get_bookmark(5);
    echo '<a href="'.$bookmark->link_url.'">'.$bookmark->link_name.'</a>';
    ?>
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文