在下拉菜单中显示计数

时间:2016-08-27 09:36:03

标签: php wordpress drop-down-menu count

我试图在下拉菜单级别显示计数,但我无法让它工作。

非常感谢任何帮助。

以下是我正在处理的代码:

function shandora_search_manufacturer_level2_field($value = array(), $class) {

$o = apply_atomic('search_manufacturer_level2_field', '', $value, $class );

if( $o != '' ) {
    return $o;
}

global $bon;
$form = $bon->form();

$loc_opt = array('any' => __('Any','bon'));

if($value['manufacturer_level1'] != '') {
    $parent = get_term_by('slug', $value['manufacturer_level1'], 'manufacturer');
    if($parent) {
        $terms = get_terms('manufacturer', array('parent' => $parent->term_id, 'hide_empty' => true, 'show_count' => 1, 'show_lisiting_count' => true, ) );
        if($terms) {
            foreach($terms as $term) {
                $loc_opt[$term->slug] = $term->name;
                $show_listing_count = bon_get_option('show_listing_count', 'yes');
                $term->name . ' (' . $term->count . ')';
            }
        }
    }
}

$o = $form->form_label(bon_get_option('manufacturer_level2_label'), 'manufacturer_level2');
$o .= $form->form_dropdown('manufacturer_level2', $loc_opt, $value['manufacturer_level2'], 'class="'.$class.'"');
if ( !empty( $terms ) && !is_wp_error( $terms ) ){
    echo '<ul>';
    foreach ( $terms as $term ) {
       echo '<li>' . $term->name . '&nbsp;(' . $term->count . ')' . '</li>';
    }
    echo '</ul>';
} 

return apply_atomic( 'search_manufacturer_level2_field_output', $o );

}

0 个答案:

没有答案
相关问题