コード例 #1
0
function nm_sub_category_menu_output($current_cat_id)
{
    global $wp_query, $nm_theme_options;
    // Categories menu divider
    $categories_menu_divider = apply_filters('nm_shop_categories_divider', '<span>&frasl;</span>');
    $output_sub_categories = '';
    // Categories order
    $orderby = 'slug';
    $order = 'asc';
    if (isset($nm_theme_options['shop_categories_orderby'])) {
        $orderby = $nm_theme_options['shop_categories_orderby'];
        $order = $nm_theme_options['shop_categories_order'];
    }
    $sub_categories = get_categories(array('type' => 'post', 'parent' => $current_cat_id, 'orderby' => $orderby, 'order' => $order, 'hide_empty' => 0, 'hierarchical' => 1, 'taxonomy' => 'product_cat'));
    $has_sub_categories = empty($sub_categories) ? false : true;
    // Is there any sub-categories available
    if ($has_sub_categories) {
        //$current_cat_name = __( 'All', 'nm-framework' );
        $current_cat_name = apply_filters('nm_shop_parent_category_title', $wp_query->queried_object->name);
        foreach ($sub_categories as $sub_category) {
            $output_sub_categories .= nm_category_menu_create_list($sub_category, $current_cat_id, $categories_menu_divider);
        }
    } else {
        $current_cat_name = $wp_query->queried_object->name;
    }
    // "Back" link
    $output_back_link = '';
    if ($nm_theme_options['shop_categories_back_link']) {
        $parent_cat_id = $wp_query->queried_object->parent;
        if ($parent_cat_id) {
            // Back to parent-category link
            $parent_cat_url = get_term_link((int) $parent_cat_id, 'product_cat');
            $output_back_link = nm_sub_category_menu_back_link($parent_cat_url, $categories_menu_divider);
        } else {
            if ($nm_theme_options['shop_categories_back_link'] == '1st') {
                // 1st sub-level - Back to top-level (main shop page) link
                $shop_page_id = wc_get_page_id('shop');
                $shop_url = get_permalink($shop_page_id);
                $output_back_link = nm_sub_category_menu_back_link($shop_url, $categories_menu_divider, ' 1st-level');
            }
        }
    }
    // Current category link
    $current_cat_url = get_term_link((int) $current_cat_id, 'product_cat');
    $output_current_cat = '<li class="current-cat"><a href="' . esc_url($current_cat_url) . '">' . esc_html($current_cat_name) . '</a></li>';
    echo $output_back_link . $output_current_cat . $output_sub_categories;
}
コード例 #2
0
function nm_sub_category_menu_output($current_cat_id)
{
    global $wp_query;
    // Categories menu divider
    $categories_menu_divider = apply_filters('nm_shop_categories_divider', '<span>&frasl;</span>');
    $output_sub_categories = '';
    // Categories order
    $orderby = 'slug';
    $order = 'asc';
    if (isset($nm_theme_options['shop_categories_orderby'])) {
        $orderby = $nm_theme_options['shop_categories_orderby'];
        $order = $nm_theme_options['shop_categories_order'];
    }
    $sub_categories = get_categories(array('type' => 'post', 'parent' => $current_cat_id, 'orderby' => $orderby, 'order' => $order, 'hide_empty' => 0, 'hierarchical' => 1, 'taxonomy' => 'product_cat'));
    $has_sub_categories = empty($sub_categories) ? false : true;
    // Is there any sub-categories available
    if ($has_sub_categories) {
        $current_cat_name = __('All', 'nm-framework');
        foreach ($sub_categories as $sub_category) {
            $output_sub_categories .= nm_category_menu_create_list($sub_category, $current_cat_id, $categories_menu_divider);
        }
    } else {
        $current_cat_name = $wp_query->queried_object->name;
    }
    // Parent category link
    $parent_cat_id = $wp_query->queried_object->parent;
    if ($parent_cat_id) {
        $parent_cat_url = get_term_link((int) $parent_cat_id, 'product_cat');
        $output_parent_cat = '<li class="nm-category-back-button"><a href="' . esc_url($parent_cat_url) . '"><i class="nm-font nm-font-arrow-left"></i> ' . esc_html__('Back', 'nm-framework') . '</a>' . $categories_menu_divider . '</li>';
    } else {
        $output_parent_cat = '';
    }
    // Current category link
    $current_cat_url = get_term_link((int) $current_cat_id, 'product_cat');
    $output_current_cat = '<li class="current-cat"><a href="' . esc_url($current_cat_url) . '">' . esc_html($current_cat_name) . '</a></li>';
    echo $output_parent_cat . $output_current_cat . $output_sub_categories;
}