12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- // 获取特定分类别名下的所有文章
- function get_posts_by_category_slug($category_slug) {
- $args = array(
- 'numberposts' => -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.= '<li><a href="/'.$flus.'?fid='.$category->term_id.'">'.$category->name.'</a></li>';
- }
- }
- 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.= '<dd><a href="/'.$flus.'?fid='.$category->term_id.'">'.$category->name.'</a></dd>';
- }
- }
- 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.= '<li class="'.($cur_id == $category->term_id ? 'on' : '').'"><a href="/'.$flus.'?fid='.$category->term_id.'"><span>>></span>'.$category->name.'</a></li>';
- }
- }
- return $li;
- }
- ?>
|