• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP walk_category_tree函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中walk_category_tree函数的典型用法代码示例。如果您正苦于以下问题:PHP walk_category_tree函数的具体用法?PHP walk_category_tree怎么用?PHP walk_category_tree使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了walk_category_tree函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: zfwca_list_categories

/**
 * Display a list categories
 * @param array $args
 * @return bool
 */
function zfwca_list_categories($args = array())
{
    $defaults = array('show_option_all' => '', 'orderby' => 'name', 'order' => 'ASC', 'show_count' => 0, 'hide_empty' => 1, 'use_desc_for_title' => 1, 'child_of' => 0, 'exclude' => '', 'include' => '', 'exclude_tree' => '', 'current_category' => 0, 'taxonomy' => 'category');
    $r = wp_parse_args($args, $defaults);
    $r['walker'] = new ZFWCA_Post_Category_Walker();
    if (!isset($r['class'])) {
        $r['class'] = 'category' == $r['taxonomy'] ? 'categories' : $r['taxonomy'];
    }
    extract($r);
    if (!taxonomy_exists($taxonomy)) {
        return false;
    }
    $categories = get_categories($r);
    $output = '';
    if (empty($categories)) {
        $output .= 'No categories';
    } else {
        if (empty($r['current_category']) && (is_category() || is_tax() || is_tag())) {
            $current_term_object = get_queried_object();
            if ($current_term_object && $r['taxonomy'] === $current_term_object->taxonomy) {
                $r['current_category'] = get_queried_object_id();
            }
        }
        $output .= walk_category_tree($categories, 0, $r);
    }
    $output = apply_filters('zfwca_wp_list_categories', $output, $args);
    return $output;
}
开发者ID:Juni4567,项目名称:meritscholarship,代码行数:33,代码来源:functions.php


示例2: wp_list_categories


//.........这里部分代码省略.........
    $defaults = array('child_of' => 0, 'current_category' => 0, 'depth' => 0, 'echo' => 1, 'exclude' => '', 'exclude_tree' => '', 'feed' => '', 'feed_image' => '', 'feed_type' => '', 'hide_empty' => 1, 'hide_title_if_empty' => false, 'hierarchical' => true, 'order' => 'ASC', 'orderby' => 'name', 'separator' => '<br />', 'show_count' => 0, 'show_option_all' => '', 'show_option_none' => __('No categories'), 'style' => 'list', 'taxonomy' => 'category', 'title_li' => __('Categories'), 'use_desc_for_title' => 1);
    $r = wp_parse_args($args, $defaults);
    if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
        $r['pad_counts'] = true;
    }
    // Descendants of exclusions should be excluded too.
    if (true == $r['hierarchical']) {
        $exclude_tree = array();
        if ($r['exclude_tree']) {
            $exclude_tree = array_merge($exclude_tree, wp_parse_id_list($r['exclude_tree']));
        }
        if ($r['exclude']) {
            $exclude_tree = array_merge($exclude_tree, wp_parse_id_list($r['exclude']));
        }
        $r['exclude_tree'] = $exclude_tree;
        $r['exclude'] = '';
    }
    if (!isset($r['class'])) {
        $r['class'] = 'category' == $r['taxonomy'] ? 'categories' : $r['taxonomy'];
    }
    if (!taxonomy_exists($r['taxonomy'])) {
        return false;
    }
    $show_option_all = $r['show_option_all'];
    $show_option_none = $r['show_option_none'];
    $categories = get_categories($r);
    $output = '';
    if ($r['title_li'] && 'list' == $r['style'] && (!empty($categories) || !$r['hide_title_if_empty'])) {
        $output = '<li class="' . esc_attr($r['class']) . '">' . $r['title_li'] . '<ul>';
    }
    if (empty($categories)) {
        if (!empty($show_option_none)) {
            if ('list' == $r['style']) {
                $output .= '<li class="cat-item-none">' . $show_option_none . '</li>';
            } else {
                $output .= $show_option_none;
            }
        }
    } else {
        if (!empty($show_option_all)) {
            $posts_page = '';
            // For taxonomies that belong only to custom post types, point to a valid archive.
            $taxonomy_object = get_taxonomy($r['taxonomy']);
            if (!in_array('post', $taxonomy_object->object_type) && !in_array('page', $taxonomy_object->object_type)) {
                foreach ($taxonomy_object->object_type as $object_type) {
                    $_object_type = get_post_type_object($object_type);
                    // Grab the first one.
                    if (!empty($_object_type->has_archive)) {
                        $posts_page = get_post_type_archive_link($object_type);
                        break;
                    }
                }
            }
            // Fallback for the 'All' link is the posts page.
            if (!$posts_page) {
                if ('page' == get_option('show_on_front') && get_option('page_for_posts')) {
                    $posts_page = get_permalink(get_option('page_for_posts'));
                } else {
                    $posts_page = home_url('/');
                }
            }
            $posts_page = esc_url($posts_page);
            if ('list' == $r['style']) {
                $output .= "<li class='cat-item-all'><a href='{$posts_page}'>{$show_option_all}</a></li>";
            } else {
                $output .= "<a href='{$posts_page}'>{$show_option_all}</a>";
            }
        }
        if (empty($r['current_category']) && (is_category() || is_tax() || is_tag())) {
            $current_term_object = get_queried_object();
            if ($current_term_object && $r['taxonomy'] === $current_term_object->taxonomy) {
                $r['current_category'] = get_queried_object_id();
            }
        }
        if ($r['hierarchical']) {
            $depth = $r['depth'];
        } else {
            $depth = -1;
            // Flat.
        }
        $output .= walk_category_tree($categories, $depth, $r);
    }
    if ($r['title_li'] && 'list' == $r['style'] && (!empty($categories) || !$r['hide_title_if_empty'])) {
        $output .= '</ul></li>';
    }
    /**
     * Filters the HTML output of a taxonomy list.
     *
     * @since 2.1.0
     *
     * @param string $output HTML output.
     * @param array  $args   An array of taxonomy-listing arguments.
     */
    $html = apply_filters('wp_list_categories', $output, $args);
    if ($r['echo']) {
        echo $html;
    } else {
        return $html;
    }
}
开发者ID:CompositeUK,项目名称:clone.WordPress-Core,代码行数:101,代码来源:category-template.php


示例3: wptouch_fdn_hierarchical_cat_list

function wptouch_fdn_hierarchical_cat_list($num, $include_count = true, $taxonomy = 'category', $opening_tag = '<ul>', $closing_tag = '</ul>')
{
    $walker = new WPtouchProMainNavMenuWalker();
    $defaults = array('number' => $num, 'show_option_all' => false, 'show_option_none' => false, 'orderby' => 'name', 'order' => 'ASC', 'style' => 'list', 'show_count' => $include_count, 'hide_empty' => 1, 'use_desc_for_title' => 1, 'child_of' => 0, 'feed' => '', 'feed_type' => '', 'feed_image' => '', 'exclude' => '', 'exclude_tree' => '', 'current_category' => 0, 'hierarchical' => true, 'title_li' => false, 'echo' => 1, 'depth' => 0, 'taxonomy' => $taxonomy, 'walker' => new WPtouchProCategoryWalker());
    if (isset($args)) {
        $r = wp_parse_args($args, $defaults);
    } else {
        $r = $defaults;
    }
    if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
        $r['pad_counts'] = true;
    }
    if (true == $r['hierarchical']) {
        $r['exclude_tree'] = $r['exclude'];
        $r['exclude'] = '';
    }
    if (!isset($r['class'])) {
        $r['class'] = 'category' == $r['taxonomy'] ? 'categories' : $r['taxonomy'];
    }
    if (!taxonomy_exists($r['taxonomy'])) {
        return false;
    }
    $show_option_all = $r['show_option_all'];
    $show_option_none = $r['show_option_none'];
    $categories = get_categories($r);
    $output = '';
    if (empty($categories)) {
        if (!empty($show_option_none)) {
            if ('list' == $r['style']) {
                $output .= '<li class="cat-item-none">' . $show_option_none . '</li>';
            } else {
                $output .= $show_option_none;
            }
        }
    } else {
        $output = $opening_tag;
        if (!empty($show_option_all)) {
            $posts_page = 'page' == get_option('show_on_front') && get_option('page_for_posts') ? get_permalink(get_option('page_for_posts')) : home_url('/');
            $posts_page = esc_url($posts_page);
            if ('list' == $r['style']) {
                $output .= "<li class='cat-item-all'><a href='{$posts_page}'>{$show_option_all}</a></li>";
            } else {
                $output .= "<a href='{$posts_page}'>{$show_option_all}</a>";
            }
        }
        if (empty($r['current_category']) && (is_category() || is_tax() || is_tag())) {
            $current_term_object = get_queried_object();
            if ($current_term_object && $r['taxonomy'] === $current_term_object->taxonomy) {
                $r['current_category'] = get_queried_object_id();
            }
        }
        if ($r['hierarchical']) {
            $depth = $r['depth'];
        } else {
            $depth = -1;
            // Flat.
        }
        $output .= walk_category_tree($categories, $depth, $r);
        $output .= '</ul>';
    }
    /**
     * Filter the HTML output of a taxonomy list.
     *
     * @since 2.1.0
     *
     * @param string $output HTML output.
     * @param array  $args   An array of taxonomy-listing arguments.
     */
    $html = apply_filters('wp_list_categories', $output, $r);
    if ($r['echo']) {
        echo $html;
    } else {
        return $html;
    }
}
开发者ID:sb-xs,项目名称:que-pour-elle,代码行数:75,代码来源:root-functions.php


示例4: wp_list_categories

function wp_list_categories($args = '')
{
    if (is_array($args)) {
        $r =& $args;
    } else {
        parse_str($args, $r);
    }
    $defaults = array('show_option_all' => '', 'orderby' => 'name', 'order' => 'ASC', 'show_last_update' => 0, 'style' => 'list', 'show_count' => 0, 'hide_empty' => 1, 'use_desc_for_title' => 1, 'child_of' => 0, 'feed' => '', 'feed_image' => '', 'exclude' => '', 'hierarchical' => true, 'title_li' => __('Categories'));
    $r = array_merge($defaults, $r);
    if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
        $r['pad_counts'] = true;
    }
    if (isset($r['show_date'])) {
        $r['include_last_update_time'] = $r['show_date'];
    }
    extract($r);
    $categories = get_categories($r);
    $output = '';
    if ($title_li && 'list' == $style) {
        $output = '<li class="categories">' . $r['title_li'] . '<ul>';
    }
    if (empty($categories)) {
        if ('list' == $style) {
            $output .= '<li>' . __("No categories") . '</li>';
        } else {
            $output .= __("No categories");
        }
    } else {
        global $wp_query;
        if (is_category()) {
            $r['current_category'] = $wp_query->get_queried_object_id();
        }
        if ($hierarchical) {
            $depth = 0;
        } else {
            $depth = -1;
        }
        // Flat.
        $output .= walk_category_tree($categories, $depth, $r);
    }
    if ($title_li && 'list' == $style) {
        $output .= '</ul></li>';
    }
    echo apply_filters('wp_list_categories', $output);
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:45,代码来源:category-template.php


示例5: wp_list_categories

/**
 * Display or retrieve the HTML list of categories.
 *
 * The list of arguments is below:
 *     'show_option_all' (string) - Text to display for showing all categories.
 *     'orderby' (string) default is 'ID' - What column to use for ordering the
 * categories.
 *     'order' (string) default is 'ASC' - What direction to order categories.
 *     'show_count' (bool|int) default is 0 - Whether to show how many posts are
 * in the category.
 *     'hide_empty' (bool|int) default is 1 - Whether to hide categories that
 * don't have any posts attached to them.
 *     'use_desc_for_title' (bool|int) default is 1 - Whether to use the
 * description instead of the category title.
 *     'feed' - See {@link get_categories()}.
 *     'feed_type' - See {@link get_categories()}.
 *     'feed_image' - See {@link get_categories()}.
 *     'child_of' (int) default is 0 - See {@link get_categories()}.
 *     'exclude' (string) - See {@link get_categories()}.
 *     'exclude_tree' (string) - See {@link get_categories()}.
 *     'echo' (bool|int) default is 1 - Whether to display or retrieve content.
 *     'current_category' (int) - See {@link get_categories()}.
 *     'hierarchical' (bool) - See {@link get_categories()}.
 *     'title_li' (string) - See {@link get_categories()}.
 *     'depth' (int) - The max depth.
 *
 * @since 2.1.0
 *
 * @param string|array $args Optional. Override default arguments.
 * @return string HTML content only if 'echo' argument is 0.
 */
function wp_list_categories($args = '')
{
    $defaults = array('show_option_all' => '', 'show_option_none' => __('No categories'), 'orderby' => 'name', 'order' => 'ASC', 'style' => 'list', 'show_count' => 0, 'hide_empty' => 1, 'use_desc_for_title' => 1, 'child_of' => 0, 'feed' => '', 'feed_type' => '', 'feed_image' => '', 'exclude' => '', 'exclude_tree' => '', 'current_category' => 0, 'hierarchical' => true, 'title_li' => __('Categories'), 'echo' => 1, 'depth' => 0, 'taxonomy' => 'category');
    $r = wp_parse_args($args, $defaults);
    if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
        $r['pad_counts'] = true;
    }
    if (true == $r['hierarchical']) {
        $r['exclude_tree'] = $r['exclude'];
        $r['exclude'] = '';
    }
    if (!isset($r['class'])) {
        $r['class'] = 'category' == $r['taxonomy'] ? 'categories' : $r['taxonomy'];
    }
    extract($r);
    if (!taxonomy_exists($taxonomy)) {
        return false;
    }
    $categories = get_categories($r);
    $output = '';
    if ($title_li && 'list' == $style) {
        $output = '<li class="' . esc_attr($class) . '">' . $title_li . '<ul>';
    }
    if (empty($categories)) {
        if (!empty($show_option_none)) {
            if ('list' == $style) {
                $output .= '<li>' . $show_option_none . '</li>';
            } else {
                $output .= $show_option_none;
            }
        }
    } else {
        if (!empty($show_option_all)) {
            $posts_page = 'page' == get_option('show_on_front') && get_option('page_for_posts') ? get_permalink(get_option('page_for_posts')) : home_url('/');
            $posts_page = esc_url($posts_page);
            if ('list' == $style) {
                $output .= "<li><a href='{$posts_page}'>{$show_option_all}</a></li>";
            } else {
                $output .= "<a href='{$posts_page}'>{$show_option_all}</a>";
            }
        }
        if (empty($r['current_category']) && (is_category() || is_tax() || is_tag())) {
            $current_term_object = get_queried_object();
            if ($r['taxonomy'] == $current_term_object->taxonomy) {
                $r['current_category'] = get_queried_object_id();
            }
        }
        if ($hierarchical) {
            $depth = $r['depth'];
        } else {
            $depth = -1;
        }
        // Flat.
        $output .= walk_category_tree($categories, $depth, $r);
    }
    if ($title_li && 'list' == $style) {
        $output .= '</ul></li>';
    }
    $output = apply_filters('wp_list_categories', $output, $args);
    if ($echo) {
        echo $output;
    } else {
        return $output;
    }
}
开发者ID:jawandsingh,项目名称:wordpress_with_sql_azure,代码行数:96,代码来源:category-template.php


示例6: avh_wp_list_categories

 /**
  * Display or retrieve the HTML list of categories.
  *
  * The list of arguments is below:
  * 'show_option_all' (string) - Text to display for showing all categories.
  * 'orderby' (string) default is 'ID' - What column to use for ordering the
  * categories.
  * 'order' (string) default is 'ASC' - What direction to order categories.
  * 'show_last_update' (bool|int) default is 0 - See {@link
  * walk_category_dropdown_tree()}
  * 'show_count' (bool|int) default is 0 - Whether to show how many posts are
  * in the category.
  * 'hide_empty' (bool|int) default is 1 - Whether to hide categories that
  * don't have any posts attached to them.
  * 'use_desc_for_title' (bool|int) default is 1 - Whether to use the
  * description instead of the category title.
  * 'feed' - See {@link get_categories()}.
  * 'feed_type' - See {@link get_categories()}.
  * 'feed_image' - See {@link get_categories()}.
  * 'child_of' (int) default is 0 - See {@link get_categories()}.
  * 'exclude' (string) - See {@link get_categories()}.
  * 'exclude_tree' (string) - See {@link get_categories()}.
  * 'echo' (bool|int) default is 1 - Whether to display or retrieve content.
  * 'current_category' (int) - See {@link get_categories()}.
  * 'hierarchical' (bool) - See {@link get_categories()}.
  * 'title_li' (string) - See {@link get_categories()}.
  * 'depth' (int) - The max depth.
  *
  * @since 2.1.0
  *
  * @param string|array $args Optional. Override default arguments.
  * @return string HTML content only if 'echo' argument is 0.
  */
 function avh_wp_list_categories($args = '', $selectedonly)
 {
     $mywalker = new AVHEC_Walker_Category();
     $defaults = array('show_option_all' => '', 'orderby' => 'name', 'order' => 'ASC', 'show_last_update' => 0, 'style' => 'list', 'show_count' => 0, 'hide_empty' => 1, 'use_desc_for_title' => 1, 'child_of' => 0, 'feed' => '', 'feed_type' => '', 'feed_image' => '', 'exclude' => '', 'exclude_tree' => '', 'current_category' => 0, 'hierarchical' => true, 'title_li' => __('Categories'), 'echo' => 1, 'depth' => 0, 'walker' => $mywalker);
     $r = wp_parse_args($args, $defaults);
     if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
         $r['pad_counts'] = true;
     }
     if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
         $r['pad_counts'] = true;
     }
     if (isset($r['show_date'])) {
         $r['include_last_update_time'] = $r['show_date'];
     }
     if (true == $r['hierarchical']) {
         $r['exclude_tree'] = $r['exclude'];
         $r['exclude'] = '';
     }
     extract($r);
     $categories = get_categories($r);
     $output = '';
     if ($title_li && 'list' == $style) {
         $output = '<li class="categories">' . $r['title_li'] . '<ul>';
     }
     if (empty($categories)) {
         if ('list' == $style) {
             $output .= '<li>' . __("No categories") . '</li>';
         } else {
             $output .= __("No categories");
         }
     } else {
         global $wp_query;
         if (!empty($show_option_all)) {
             if ('list' == $style) {
                 $output .= '<li><a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a></li>';
             } else {
                 $output .= '<a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a>';
             }
         }
         if (empty($r['current_category']) && is_category()) {
             $r['current_category'] = $wp_query->get_queried_object_id();
         }
         if ($hierarchical) {
             $depth = $r['depth'];
         } else {
             $depth = -1;
             // Flat.
         }
         $output .= walk_category_tree($categories, $depth, $r);
     }
     if ($title_li && 'list' == $style) {
         $output .= '</ul></li>';
     }
     $output = apply_filters('wp_list_categories', $output);
     if ($echo) {
         echo $output;
     } else {
         return $output;
     }
 }
开发者ID:pjsinco,项目名称:doctorsthatdo-wp-content,代码行数:93,代码来源:avh-ec.core.php


示例7: wp_list_categories

/**
 * Display or retrieve the HTML list of categories.
 *
 * The list of arguments is below:
 *     'show_option_all' (string) - Text to display for showing all categories.
 *     'orderby' (string) default is 'ID' - What column to use for ordering the
 * categories.
 *     'order' (string) default is 'ASC' - What direction to order categories.
 *     'show_last_update' (bool|int) default is 0 - See {@link
 * walk_category_dropdown_tree()}
 *     'show_count' (bool|int) default is 0 - Whether to show how many posts are
 * in the category.
 *     'hide_empty' (bool|int) default is 1 - Whether to hide categories that
 * don't have any posts attached to them.
 *     'use_desc_for_title' (bool|int) default is 1 - Whether to use the
 * description instead of the category title.
 *     'feed' - See {@link get_categories()}.
 *     'feed_type' - See {@link get_categories()}.
 *     'feed_image' - See {@link get_categories()}.
 *     'child_of' (int) default is 0 - See {@link get_categories()}.
 *     'exclude' (string) - See {@link get_categories()}.
 *     'exclude_tree' (string) - See {@link get_categories()}.
 *     'echo' (bool|int) default is 1 - Whether to display or retrieve content.
 *     'current_category' (int) - See {@link get_categories()}.
 *     'hierarchical' (bool) - See {@link get_categories()}.
 *     'title_li' (string) - See {@link get_categories()}.
 *     'depth' (int) - The max depth.
 *
 * @since 2.1.0
 *
 * @param string|array $args Optional. Override default arguments.
 * @return string HTML content only if 'echo' argument is 0.
 */
function wp_list_categories($args = '')
{
    $defaults = array('show_option_all' => '', 'show_option_none' => __('No categories'), 'orderby' => 'name', 'order' => 'ASC', 'show_last_update' => 0, 'style' => 'list', 'show_count' => 0, 'hide_empty' => 1, 'use_desc_for_title' => 1, 'child_of' => 0, 'feed' => '', 'feed_type' => '', 'feed_image' => '', 'exclude' => '', 'exclude_tree' => '', 'current_category' => 0, 'hierarchical' => true, 'title_li' => __('Categories'), 'echo' => 1, 'depth' => 0, 'taxonomy' => 'category');
    $r = wp_parse_args($args, $defaults);
    if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
        $r['pad_counts'] = true;
    }
    if (isset($r['show_date'])) {
        $r['include_last_update_time'] = $r['show_date'];
    }
    if (true == $r['hierarchical']) {
        $r['exclude_tree'] = $r['exclude'];
        $r['exclude'] = '';
    }
    if (!isset($r['class'])) {
        $r['class'] = 'category' == $r['taxonomy'] ? 'categories' : $r['taxonomy'];
    }
    extract($r);
    if (!taxonomy_exists($taxonomy)) {
        return false;
    }
    $categories = get_categories($r);
    $output = '';
    if ($title_li && 'list' == $style) {
        $output = '<li class="' . $class . '">' . $title_li . '<ul>';
    }
    if (empty($categories)) {
        if (!empty($show_option_none)) {
            if ('list' == $style) {
                $output .= '<li>' . $show_option_none . '</li>';
            } else {
                $output .= $show_option_none;
            }
        }
    } else {
        global $wp_query;
        if (!empty($show_option_all)) {
            if ('list' == $style) {
                $output .= '<li><a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a></li>';
            } else {
                $output .= '<a href="' . get_bloginfo('url') . '">' . $show_option_all . '</a>';
            }
        }
        if (empty($r['current_category']) && (is_category() || is_tax())) {
            $r['current_category'] = $wp_query->get_queried_object_id();
        }
        if ($hierarchical) {
            $depth = $r['depth'];
        } else {
            $depth = -1;
        }
        // Flat.
        $output .= walk_category_tree($categories, $depth, $r);
    }
    if ($title_li && 'list' == $style) {
        $output .= '</ul></li>';
    }
    $output = apply_filters('wp_list_categories', $output, $args);
    if ($echo) {
        echo $output;
    } else {
        return $output;
    }
}
开发者ID:hacklabr,项目名称:toquenobrasil,代码行数:97,代码来源:category-template.php


示例8: avh_wp_list_categories


//.........这里部分代码省略.........
  * }
  * @return false|string HTML content only if 'echo' argument is 0.
  */
 public function avh_wp_list_categories($args = '')
 {
     $mywalker = new AVHEC_Walker_Category();
     $defaults = array('child_of' => 0, 'current_category' => 0, 'depth' => 0, 'echo' => 1, 'exclude' => '', 'exclude_tree' => '', 'feed' => '', 'feed_image' => '', 'feed_type' => '', 'hide_empty' => 1, 'hide_title_if_empty' => false, 'hierarchical' => true, 'order' => 'ASC', 'orderby' => 'name', 'separator' => '<br />', 'show_count' => 0, 'show_last_update' => 0, 'show_option_all' => '', 'show_option_none' => __('No categories'), 'style' => 'list', 'taxonomy' => 'category', 'title_li' => __('Categories'), 'use_desc_for_title' => 1, 'walker' => $mywalker);
     $r = wp_parse_args($args, $defaults);
     if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
         $r['pad_counts'] = true;
     }
     if (isset($r['show_date'])) {
         $r['include_last_update_time'] = $r['show_date'];
     }
     if (true == $r['hierarchical']) {
         $exclude_tree = array();
         if ($r['exclude_tree']) {
             $exclude_tree = array_merge($exclude_tree, wp_parse_id_list($r['exclude_tree']));
         }
         if ($r['exclude']) {
             $exclude_tree = array_merge($exclude_tree, wp_parse_id_list($r['exclude']));
         }
         $r['exclude_tree'] = $exclude_tree;
         $r['exclude'] = '';
     }
     if (!isset($r['class'])) {
         $r['class'] = 'category' == $r['taxonomy'] ? 'categories' : $r['taxonomy'];
     }
     if (!taxonomy_exists($r['taxonomy'])) {
         return false;
     }
     $show_option_all = $r['show_option_all'];
     $show_option_none = $r['show_option_none'];
     $categories = get_categories($r);
     $output = '';
     if ($r['title_li'] && 'list' == $r['style'] && (!empty($categories) || !$r['hide_title_if_empty'])) {
         $output = '<li class="' . esc_attr($r['class']) . '">' . $r['title_li'] . '<ul>';
     }
     if (empty($categories)) {
         if (!empty($show_option_none)) {
             if ('list' == $r['style']) {
                 $output .= '<li class="cat-item-none">' . __("No categories") . '</li>';
             } else {
                 $output .= $show_option_none;
             }
         }
     } else {
         if (!empty($show_option_all)) {
             $posts_page = '';
             $taxonomy_object = get_taxonomy($r['taxonomy']);
             if (!in_array('post', $taxonomy_object->object_type) && !in_array('page', $taxonomy_object->object_type)) {
                 foreach ($taxonomy_object->object_type as $object_type) {
                     $_object_type = get_post_type_object($object_type);
                     // Grab the first one.
                     if (!empty($_object_type->has_archive)) {
                         $posts_page = get_post_type_archive_link($object_type);
                         break;
                     }
                 }
             }
             // Fallback for the 'All' link is the posts page.
             if (!$posts_page) {
                 if ('page' == get_option('show_on_front') && get_option('page_for_posts')) {
                     $posts_page = get_permalink(get_option('page_for_posts'));
                 } else {
                     $posts_page = home_url('/');
                 }
             }
             $posts_page = esc_url($posts_page);
             if ('list' == $r['style']) {
                 $output .= '<li class="cat-item-all"><a href="' . $posts_page . '">' . $show_option_all . '</a></li>';
             } else {
                 $output .= '<a href="' . $posts_page . '">' . $show_option_all . '</a>';
             }
         }
         if (empty($r['current_category']) && (is_category() || is_tax() || is_tag())) {
             $current_term_object = get_queried_object();
             if ($current_term_object && $r['taxonomy'] === $current_term_object->taxonomy) {
                 $r['current_category'] = get_queried_object_id();
             }
         }
         if ($r['hierarchical']) {
             $depth = $r['depth'];
         } else {
             $depth = -1;
             // Flat.
         }
         $output .= walk_category_tree($categories, $depth, $r);
     }
     if ($r['title_li'] && 'list' == $r['style']) {
         $output .= '</ul></li>';
     }
     $html = apply_filters('wp_list_categories', $output, $args);
     if ($r['echo']) {
         echo $html;
     } else {
         return $html;
     }
     return;
 }
开发者ID:uwmadisoncals,项目名称:Cluster-Plugins,代码行数:101,代码来源:avh-ec.core.php


示例9: wp_list_categories_for_posts

function wp_list_categories_for_posts($args = '')
{
    $defaults = array('show_option_all' => '', 'show_option_none' => __('No categories'), 'orderby' => 'name', 'order' => 'ASC', 'style' => 'list', 'show_count' => 0, 'hide_empty' => 1, 'use_desc_for_title' => 1, 'child_of' => 0, 'feed' => '', 'feed_type' => '', 'feed_image' => '', 'exclude' => '', 'exclude_tree' => '', 'current_category' => 0, 'hierarchical' => true, 'title_li' => __('Categories'), 'echo' => 1, 'depth' => 0, 'taxonomy' => 'category');
    $r = wp_parse_args($args, $defaults);
    if (!isset($r['pad_counts']) && $r['show_count'] && $r['hierarchical']) {
        $r['pad_counts'] = true;
    }
    if (true == $r['hierarchical']) {
        $r['exclude_tree'] = $r['exclude'];
        $r['exclude'] = '';
    }
    if (!isset($r['class'])) {
        $r['class'] = 'category' == $r['taxonomy'] ? 'categories' : $r['taxonomy'];
    }
    if (!taxonomy_exists($r['taxonomy'])) {
        return false;
    }
    $show_option_all = $r['show_option_all'];
    $show_option_none = $r['show_option_none'];
    $categories = get_categories($r);
    foreach ($categories as $key => $category) {
        add_filter('posts_where', 'related_posts_where');
        $rPosts = new WP_Query(array('post_type' => array('post'), 'posts_per_page' => -1, 'is_single' => true, 'no_found_rows' => true, 'post_status' => array('publish'), 'ignore_sticky_posts' => true, 'cat' => $category->cat_ID));
        // If no posts found, ...
        if ($rPosts->post_count == 0) {
            unset($categories[$key]);
        } else {
            $categories[$key]->count = $rPosts->post_count;
        }
    }
    $output = '';
    if ($r['title_li'] && 'list' == $r['style']) {
        $output = '<li class="' . esc_attr($r['class']) . '">' . $r['title_li'] . '<ul>';
    }
    if (empty($categories)) {
        if (!empty($show_option_none)) {
            if ('list' == $r['style']) {
                $output .= '<li class="cat-item-none">' . $show_option_none . '</li>';
            } else {
                $output .= $show_option_none;
            }
        }
    } else {
        if (!empty($show_option_all)) {
            $posts_page = 'page' == get_option('show_on_front') && get_option('page_for_posts') ? get_permalink(get_option('page_for_posts')) : home_url('/');
            $posts_page = esc_url($posts_page);
            if ('list' == $r['style']) {
                $output .= "<li class='cat-item-all'><a href='{$posts_page}'>{$show_option_all}</a></li>";
            } else {
                $output .= "<a href='{$posts_page}'>{$show_option_all}</a>";
            }
        }
        if (empty($r['current_category']) && (is_category() || is_tax() || is_tag())) {
            $current_term_object = get_queried_object();
            if ($current_term_object && $r['taxonomy'] === $current_term_object->taxonomy) {
                $r['current_category'] = get_queried_object_id();
            }
        }
        if ($r['hierarchical']) {
            $depth = $r['depth'];
        } else {
            $depth = -1;
            // Flat.
        }
        $output .= walk_category_tree($categories, $depth, $r);
    }
    if ($r['title_li'] && 'list' == $r['style']) {
        $output .= '</ul></li>';
    }
    /**
     * Filter the HTML output of a taxonomy list.
     *
     * @since 2.1.0
     *
     * @param string $output HTML output.
     * @param array  $args   An array of taxonomy-listing arguments.
     */
    $html = apply_filters('wp_list_categories', $output, $args);
    wp_reset_postdata();
    if ($r['echo']) {
        echo $html;
    } else {
        return $html;
    }
}
开发者ID:navnorth,项目名称:wp-oii-theme,代码行数:85,代码来源:functions.php



注:本文中的walk_category_tree函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP walk_nav_menu_tree函数代码示例发布时间:2022-05-23
下一篇:
PHP walk_category_dropdown_tree函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap