WordPress Tricks #3


So here’s some more useful code for when WordPress, in its almighty awesomeness, forgets bits and pieces..
Let’s get started with a trick and a half: how to display WordPress categories called by wp_list_categories, one next to the other, also adding a separator in between them, but without showing it even after the last category.

In case you actually want the separator to show up even after the last category, use this other bit of code instead:

And now a cookie for you, a function I made some time ago for Vivanotte.it, to simplify and automate post images displaying in any part of the template I wanted.
You will need timthumb for this, you will put it in a scripts folder, inside your template (put timthumbs.php and create an empty folder cache, making sure it’s writeable).
Then go ahead and put the code below in your template functions.php (not there? create it).

Moreover, thanks to timthumb, we can resize images nicely with any size we want and also have the images cached, so that the server doesn’t have to cry in pain, resizing every image each time run-time.

So basically, the function looks for, in priority order: Featured post image, image link added through a custom field thumb inside the post, any image uploaded inside the post.
The first one that it finds, will be the one displayed wherever we want in the template.

I’ve already SEOd the function, so that every image is validated and SEO friendly, with its alt = post title.
Pretty obvious but nontheless worth to mention, in case you want to link every displayed image to its post, follow the instructions:

So, to display post images anywhere in your template, simply use inside a loop:

Enjoy!

I’m a Digital Consultant, Web Designer & Developer, specialized in WordPress.
I’ve been making websites for 17 years and have specialized in WordPress since 2009.
I like to work with PHP/MySQL, HTML5/CSS3/Javascript, Twitter Bootstrap and, of course, WordPress.
I help companies, professionals and startups grow with technology, I hand-pick the perfect team for them, plan projects from the ground-up, develop & deploy websites, online stores and apps.