_sort_nav_menu_items() - WordPress 函数参考中文文档

返回介绍

_sort_nav_menu_items()

发布于 2017-09-11 字数 2090 浏览 856 评论 0

Warning: This function has been deprecated. Use wp_list_sort() instead.

Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

_sort_nav_menu_items( object $a,  object $b )

Sort menu items by the desired key.


描述


参数

$a

(object)
(Required)
The first object to compare

$b

(object)
(Required)
The second object to compare


返回值

(int) -1, 0, or 1 if $a is considered to be respectively less than, equal to, or greater than $b.


源代码

File: wp-includes/deprecated.php

function _sort_nav_menu_items( $a, $b ) {
	global $_menu_item_sort_prop;

	_deprecated_function( __FUNCTION__, '4.7.0', 'wp_list_sort' );

	if ( empty( $_menu_item_sort_prop ) )
		return 0;

	if ( ! isset( $a->$_menu_item_sort_prop ) || ! isset( $b->$_menu_item_sort_prop ) )
		return 0;

	$_a = (int) $a->$_menu_item_sort_prop;
	$_b = (int) $b->$_menu_item_sort_prop;

	if ( $a->$_menu_item_sort_prop == $b->$_menu_item_sort_prop )
		return 0;
	elseif ( $_a == $a->$_menu_item_sort_prop && $_b == $b->$_menu_item_sort_prop )
		return $_a < $_b ? -1 : 1;
	else
		return strcmp( $a->$_menu_item_sort_prop, $b->$_menu_item_sort_prop );
}

更新日志

Version 描述
4.7.0 Use wp_list_sort()
3.0.0 Introduced.

相关函数

Uses

  • wp-includes/functions.php:
    _deprecated_function()

User Contributed Notes

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!