2016-10-06 19 views
2

請幫我更改此代碼顯示的項目,他們的數量= 0 ,也是我想的名字之間加空格和計數我應該如何更改此代碼以顯示空白區域?

$args = array('hide_empty=0'); 

$terms = get_terms('job_region', $args); 
if (!empty($terms) && !is_wp_error($terms)) { 
$count = count($terms); 
$i = 0; 
$term_list = '<ul class="statelist clearfix">'; 
foreach($terms as $term) { 
    $i++; 
    $term_list. = '<li count-all='.$term - > count. 
    '><a href="/job-search/?location='.$term - > name. 
    '&submit=true" title="'.esc_attr(sprintf(__('نمایش آگهی های %s', 'my_localization_domain'), $term - > name)). 
    '">'.$term - > name. 
    '('.$term - > count. 
    ')'. 
    '</a></li>'; 
    if ($count != $i) { 
     $term_list. = " "; 
    } else { 
     $term_list. = '</ul>'; 
    } 
} 
echo $term_list; 
} 

回答

1

這應該做的伎倆爲您提供: -

$terms = get_terms(array(
    'taxonomy' => 'job_region', 
    'hide_empty' => false, 
)); 

if (!empty($terms) && !is_wp_error($terms)) { 
$count = count($terms); 
$i = 0; 
$term_list = '<ul class="statelist clearfix">'; 
foreach($terms as $term) { 
    $i++; 
    $term_list. = '<li count-all='.$term - > count. 
    '><a href="/job-search/?location='.$term - > name. 
    '&submit=true" title="'.esc_attr(sprintf(__('نمایش آگهی های %s', 'my_localization_domain'), $term - > name)). 
    '">'.$term - > name. 
    ' ('.$term - > count. 
    ')'. 
    '</a></li>'; 
    if ($count != $i) { 
     $term_list. = " "; 
    } else { 
     $term_list. = '</ul>'; 
    } 
} 
echo $term_list; 
} 

您可以閱讀更多@https://developer.wordpress.org/reference/functions/get_terms/