Search

菜單問題,似乎不可行

/* 自動給導(dǎo)航菜單中的分類添加其下的子分類 */
add_filter(“wp_get_nav_menu_items”, function($items, $menu, $args) {
if (is_admin()) {
return $items;
}

foreach ($items as $index => $i) {
if (“category” !== $i->object) {
continue;
}
$term_children = get_term_children($i->object_id, “category”);
foreach ($term_children as $index2 => $child_id) {
$child = get_term($child_id);
$url = get_term_link($child);
$e = new stdClass();
$e->title = $child->name;
$e->url = $url;
$e->menu_order = 500 * ($index + 1) + $index2;
$e->post_type = “nav_menu_item”;
$e->post_status = “published”;
$e->post_parent = $i->ID;
$e->menu_item_parent = $i->ID;
$e->type = “custom”;
$e->object = “custom”;
$e->ID = 0;
$e->db_id = 0;
$e->object_id = 0;
$e->classes = array();
$e->description = “”;
$items[] = $e;
}
}
return $items;
}, 10, 3);

目錄
四平市| 开江县| 兴和县| 兰坪| 吉安市| 广丰县| 苍南县| 和政县| 大宁县| 尼玛县| 五峰| 和平区| 郑州市| 雅安市| 和政县| 金溪县| 浪卡子县| 静乐县| 西峡县| 秭归县| 闸北区| 遂昌县| 商洛市| 海原县| 新绛县| 新河县| 含山县| 楚雄市| 天水市| 黔西县| 泉州市| 全州县| 天等县| 东港市| 镇巴县| 望谟县| 兴业县| 博客| 延边| 嘉峪关市| 肇州县|