Skip to content

Instantly share code, notes, and snippets.

@sarahmonster
Created August 22, 2016 13:22
Show Gist options
  • Save sarahmonster/ecf38e8134a8f921f9a40a778d4ec2ed to your computer and use it in GitHub Desktop.
Save sarahmonster/ecf38e8134a8f921f9a40a778d4ec2ed to your computer and use it in GitHub Desktop.
Adds a span around post counts in category archives widget and general archives widgets. This allows for easy styling of the count—for instance, using leading dots. (The SCSS file adds leading dots.)
/**
* Filter the categories archive widget to add a span around post count
*/
function smittenkitchen_cat_count_span( $links ) {
$links = str_replace( '</a> (', '</a><span class="post-count">(', $links );
$links = str_replace( ')', ')</span>', $links );
return $links;
}
add_filter( 'wp_list_categories', 'smittenkitchen_cat_count_span' );
/**
* Filter the archives widget to add a span around post count
*/
function smittenkitchen_archive_count_span( $links ) {
$links = str_replace( '</a>&nbsp;(', '</a><span class="post-count">(', $links );
$links = str_replace( ')', ')</span>', $links );
return $links;
}
add_filter( 'get_archives_link', 'smittenkitchen_archive_count_span' );
/* Archive widgets */
.widget_archive,
.widget_categories {
ul li {
align-items: baseline;
display: flex;
flex-wrap: wrap;
a {
border: none;
order: 1;
&:hover {
background-color: transparent;
}
}
&::before {
border-bottom: 1px dotted $color__light-grey;
content: "";
flex-grow: 1;
order: 2;
margin: 0.25em 3px;
} // :before
.post-count {
order: 3;
padding-top: 0.5em;
}
ul {
order: 4;
flex-grow: 0;
flex-basis: 100%;
margin-left: 1em;
}
} // ul li
} // .widget_archive, .widget_categories
@munkhbayaryo
Copy link

Nice. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment