admin管理员组文章数量:1026114
I am using the below code to display the list (radio buttons) of terms that are currently used by existing custom post type posts:
$args = array(
'taxonomy' => 'typ',
'post_type' => 'instytucje',
);
$terms = get_terms('typ', $args);
$count = count($terms); $i=0;
if ($count > 0) {
$cape_list = '';
foreach ($terms as $term) {
$i++;
$term_list .= '<input type="radio" name="typ" value="' . $term->slug . '"> ' . $term->name . '';
if ($count != $i) $term_list .= '<br>'; else $term_list .= '<br>';
}
echo '<form name="filterby" action="" method="GET">';
echo $term_list;
echo '<button OnClick="document.filterby.submit();">Szukaj</button>';
}
The list is used as a form to filter posts by terms.
My question is - how can I add a counter showing the number of posts next to each term on the list?
[radio button] [term name] [number of posts with the term]
This is the site I am working on:
/
I am using the below code to display the list (radio buttons) of terms that are currently used by existing custom post type posts:
$args = array(
'taxonomy' => 'typ',
'post_type' => 'instytucje',
);
$terms = get_terms('typ', $args);
$count = count($terms); $i=0;
if ($count > 0) {
$cape_list = '';
foreach ($terms as $term) {
$i++;
$term_list .= '<input type="radio" name="typ" value="' . $term->slug . '"> ' . $term->name . '';
if ($count != $i) $term_list .= '<br>'; else $term_list .= '<br>';
}
echo '<form name="filterby" action="" method="GET">';
echo $term_list;
echo '<button OnClick="document.filterby.submit();">Szukaj</button>';
}
The list is used as a form to filter posts by terms.
My question is - how can I add a counter showing the number of posts next to each term on the list?
[radio button] [term name] [number of posts with the term]
This is the site I am working on:
http://www.marketingpolityczny/baza-wiedzy/instytucje/
1 Answer
Reset to default 0Replace the 11th line with the code below (untested):
$term_list .= '<input type="radio" name="typ" value="' . $term->slug . '"> ' . $term->name . ' Number of Posts:'. $term->count;
It appears that get_terms has a post count return value.
I am using the below code to display the list (radio buttons) of terms that are currently used by existing custom post type posts:
$args = array(
'taxonomy' => 'typ',
'post_type' => 'instytucje',
);
$terms = get_terms('typ', $args);
$count = count($terms); $i=0;
if ($count > 0) {
$cape_list = '';
foreach ($terms as $term) {
$i++;
$term_list .= '<input type="radio" name="typ" value="' . $term->slug . '"> ' . $term->name . '';
if ($count != $i) $term_list .= '<br>'; else $term_list .= '<br>';
}
echo '<form name="filterby" action="" method="GET">';
echo $term_list;
echo '<button OnClick="document.filterby.submit();">Szukaj</button>';
}
The list is used as a form to filter posts by terms.
My question is - how can I add a counter showing the number of posts next to each term on the list?
[radio button] [term name] [number of posts with the term]
This is the site I am working on:
/
I am using the below code to display the list (radio buttons) of terms that are currently used by existing custom post type posts:
$args = array(
'taxonomy' => 'typ',
'post_type' => 'instytucje',
);
$terms = get_terms('typ', $args);
$count = count($terms); $i=0;
if ($count > 0) {
$cape_list = '';
foreach ($terms as $term) {
$i++;
$term_list .= '<input type="radio" name="typ" value="' . $term->slug . '"> ' . $term->name . '';
if ($count != $i) $term_list .= '<br>'; else $term_list .= '<br>';
}
echo '<form name="filterby" action="" method="GET">';
echo $term_list;
echo '<button OnClick="document.filterby.submit();">Szukaj</button>';
}
The list is used as a form to filter posts by terms.
My question is - how can I add a counter showing the number of posts next to each term on the list?
[radio button] [term name] [number of posts with the term]
This is the site I am working on:
http://www.marketingpolityczny/baza-wiedzy/instytucje/
1 Answer
Reset to default 0Replace the 11th line with the code below (untested):
$term_list .= '<input type="radio" name="typ" value="' . $term->slug . '"> ' . $term->name . ' Number of Posts:'. $term->count;
It appears that get_terms has a post count return value.
本文标签: How to add a post counter to the list of custom taxonomy terms
版权声明:本文标题:How to add a post counter to the list of custom taxonomy terms? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745626650a2159903.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论