sort_menu

函式
sort_menu ( $a, $b )
引數
  • (array) $a
    Required:
  • (array) $b
    Required:
返回值
  • (int)
定義位置
相關方法
_sort_nav_menu_itemsis_nav_menuurl_shortenstartelementhas_nav_menu
引入
-
棄用
-

sort_menu:這個鉤子用來修改選單項在WordPress管理儀表盤上的顯示順序。你可以使用這個鉤子來改變選單項的順序,或者向選單中新增新的專案。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function sort_menu( $a, $b ) {
global $menu_order, $default_menu_order;
$a = $a[2];
$b = $b[2];
if ( isset( $menu_order[ $a ] ) && ! isset( $menu_order[ $b ] ) ) {
return -1;
} elseif ( ! isset( $menu_order[ $a ] ) && isset( $menu_order[ $b ] ) ) {
return 1;
} elseif ( isset( $menu_order[ $a ] ) && isset( $menu_order[ $b ] ) ) {
if ( $menu_order[ $a ] == $menu_order[ $b ] ) {
return 0;
}
return ( $menu_order[ $a ] < $menu_order[ $b ] ) ? -1 : 1;
} else {
return ( $default_menu_order[ $a ] <= $default_menu_order[ $b ] ) ? -1 : 1;
}
}
usort( $menu, 'sort_menu' );
unset( $menu_order, $default_menu_order );
}
function sort_menu( $a, $b ) { global $menu_order, $default_menu_order; $a = $a[2]; $b = $b[2]; if ( isset( $menu_order[ $a ] ) && ! isset( $menu_order[ $b ] ) ) { return -1; } elseif ( ! isset( $menu_order[ $a ] ) && isset( $menu_order[ $b ] ) ) { return 1; } elseif ( isset( $menu_order[ $a ] ) && isset( $menu_order[ $b ] ) ) { if ( $menu_order[ $a ] == $menu_order[ $b ] ) { return 0; } return ( $menu_order[ $a ] < $menu_order[ $b ] ) ? -1 : 1; } else { return ( $default_menu_order[ $a ] <= $default_menu_order[ $b ] ) ? -1 : 1; } } usort( $menu, 'sort_menu' ); unset( $menu_order, $default_menu_order ); }
function sort_menu( $a, $b ) {
		global $menu_order, $default_menu_order;
		$a = $a[2];
		$b = $b[2];
		if ( isset( $menu_order[ $a ] ) && ! isset( $menu_order[ $b ] ) ) {
			return -1;
		} elseif ( ! isset( $menu_order[ $a ] ) && isset( $menu_order[ $b ] ) ) {
			return 1;
		} elseif ( isset( $menu_order[ $a ] ) && isset( $menu_order[ $b ] ) ) {
			if ( $menu_order[ $a ] == $menu_order[ $b ] ) {
				return 0;
			}
			return ( $menu_order[ $a ] < $menu_order[ $b ] ) ? -1 : 1;
		} else {
			return ( $default_menu_order[ $a ] <= $default_menu_order[ $b ] ) ? -1 : 1;
		}
	}

	usort( $menu, 'sort_menu' );
	unset( $menu_order, $default_menu_order );
}

常見問題

FAQs
檢視更多 >