Today, I modified my sidebar (specifically my category listings) to show how many posts are linked to their respective parent. This was yet another enlightening way that WP is teaching me “code”, so I thought I would share my short experience.
First, I needed to clean up the code that I was using from The Spiderbox’s sidebar:
As you can see, I was using the list_cats function which uses a long query string of arguments to achieve your desired output. Personally, this is a mess…especially if your sidebar is full of code (as is Spider’s).
What I chose to use instead, was wp_list_cats, which uses text based query strings. This is much easier and makes the code look and feel cleaner:
Ironically, this created problems for me here at Uber because my CSS was using “display:block”…my category numbers were displaying under their respective titles, not to the right as I wanted. So, I needed to change my CSS to use “display:inline” and add “padding:3px 0 0 0;” to properly display these numbers.
For those of you who are just learning CSS, I offer a little tip that helped me out when I was first learning to read code such as “padding:0 0 0 0;” and “margin:0 0 0 0;”. The first number is the top of the item to which you are applying the rule. From there, just go clock-wise and you’ll read the rest as: right, bottom, left.
