further
Member
Posted 3 years ago #
Hello!
I'd like to get a post count on tags and categories once I open the archive page, next to the tag or category name.
You can see an example of what i mean here:
http://www.elblogalternativo.com/author/angel-de-la-guarda/
(Los artÃculos de Angel de la Guarda (154):)
I managed to get the category and tag name (single_cat_title and single_tag_title), but i've not found a tread dealing with this issue.
Many thanks in advance!
Erik.
Might be more than you need but try this in your archive.php:
<?php
$term_id='';
if ( is_tag() ) {
$term_id = get_query_var('tag_id');
$taxonomy = 'post_tag';
$title = 'Tag: ';
}
if ( is_category() ) {
$term_id = get_query_var('cat');
$taxonomy = 'category';
$title = 'Category: ';
}
if ($term_id) {
$args ='include=' . $term_id;
$terms = get_terms( $taxonomy, $args );
if ($terms) {
foreach($terms as $term) {
if ($term->count > 0) {
echo '<p>' . $title . '<a href="' . get_term_link( $term->term_id, $taxonomy ) . '" title="' . sprintf( __( "View all posts in %s" ), $term->name ) . '" ' . '>' . $term->name.'</a> has ' . $term->count . ' post(s). </p> ';
}
}
}
}
?>
further
Member
Posted 3 years ago #
MichaelH, it works perfectly!
I spent like 3 hours last week looking into the forums for a solution like this one and I found several other people with the same issue and no answer, you might wanna consider publishing it into the codex or something, it works fantastic!
Many thanks,
Erik.
Eric - can you recommend a place in Codex to put that? Thanks.
gerbus3
Member
Posted 2 years ago #
Agreed, that's beautiful and rare.