Created
August 22, 2016 13:22
-
-
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.)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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> (', '</a><span class="post-count">(', $links ); | |
$links = str_replace( ')', ')</span>', $links ); | |
return $links; | |
} | |
add_filter( 'get_archives_link', 'smittenkitchen_archive_count_span' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice. Thank you!