我该如何更改此代码以显示空白区域?

时间:2016-10-06 10:38:22

标签: php html wordpress

请帮我更改此代码以显示其count = 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 个答案:

答案 0 :(得分: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/