2016-10-06 18 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/