我在wordpress上设置了一个菜单(类别),我想根据该菜单上的类别创建查询,每个菜单项一个查询
有什么想法吗?
发布于 2016-03-24 12:59:13
如果您说的是普通WP菜单系统,您可以按菜单的位置获取菜单数据,如下所示:
function custom_menu_output( $theme_location ) {
if ( ($theme_location) && ($locations = get_nav_menu_locations()) && isset($locations[$theme_location]) ) {
$menu = get_term( $locations[$theme_location], 'nav_menu' );
$menu_items = wp_get_nav_menu_items($menu->term_id);
foreach( $menu_items as $menu_item ) {
$args = array( 'category_name' => $menu_item->title);
//Do your query here & everything else
}
}
}https://stackoverflow.com/questions/36197976
复制相似问题