當(dāng)我們在WordPress后臺(tái)添加了多個(gè)自定義文章類型的時(shí)候,后臺(tái)菜單的順序往往會(huì)變得混亂不堪,這時(shí)候,對后臺(tái)菜單進(jìn)行一下排序是非常有必要的,如果我們是通過代碼添加的自定義文章類型,只需要注意添加的順序即可。如果我們是通過插件添加的,就的通過WordPress的’menu_order’這個(gè)過濾器進(jìn)行調(diào)整了。
對后臺(tái)管理菜單排序的代碼
function custom_menu_order($menu_ord) {
if (!$menu_ord) return true;
return array(
'index.php', // this represents the dashboard link
'edit.php?post_type=events', //自定義文章類型菜單
'edit.php?post_type=news',
'edit.php?post_type=articles',
'edit.php?post_type=faqs',
'edit.php?post_type=mentors',
'edit.php?post_type=testimonials',
'edit.php?post_type=services',
'edit.php?post_type=page', //默認(rèn)的頁面菜單
'edit.php', //默認(rèn)的文章菜單
);
}
add_filter('custom_menu_order', 'custom_menu_order');
add_filter('menu_order', 'custom_menu_order');
從代碼中可以看出,排序是直接通過后臺(tái)網(wǎng)址實(shí)現(xiàn)的,非常直觀方便。把以上代碼添加到當(dāng)前WordPress主題的function.php文件里,再回到后臺(tái)刷新一下,看以看到后臺(tái)管理菜單已經(jīng)按照我們的需要排好順序了。


