-1, // 获取所有文章 'post_type' => 'post', // 文章类型 'category_name' => $category_slug, // 分类别名 'orderby' => 'date', // 按日期排序 'order' => 'ASC', // 降序排序 ); $posts = get_posts($args); return $posts; } // 获取特定分类下所有子目录 function get_subdirectories($parent_category_id) { $args = array( 'parent' => $parent_category_id, 'taxonomy' => 'category', 'hide_empty' => false, 'exclude' => array($parent_category_id), // 排除父分类本身 'orderby' => 'id', // 按日期排序 'order' => 'ASC', // 降序排序 ); $subcategories = get_terms( $args ); return $subcategories; } // 返回并输出下拉菜单 function get_submenus($flus, $parent_category_id) { $subdirs = get_subdirectories($parent_category_id); $li = ''; if ( !empty( $subdirs ) && !is_wp_error( $subdirs ) ) { foreach ( $subdirs as $category ) { $li.= '
  • '.$category->name.'
  • '; } } return $li; } // 底部菜单导航 function get_footer_submenus($flus, $parent_category_id) { $subdirs = get_subdirectories($parent_category_id); $li = ''; if ( !empty( $subdirs ) && !is_wp_error( $subdirs ) ) { foreach ( $subdirs as $category ) { $li.= '
    '.$category->name.'
    '; } } return $li; } // 输出左侧栏菜单 function get_slider_submenus($flus, $parent_category_id, $cur_id) { $subdirs = get_subdirectories($parent_category_id); $li = ''; if ( !empty( $subdirs ) && !is_wp_error( $subdirs ) ) { foreach ( $subdirs as $category ) { $li.= '
  • >>'.$category->name.'
  • '; } } return $li; } ?>