I have a category in my blog called “work”, and I will be assigning each post a thumbnail.
This category will be excluded from my blog’s navigation, but added as a fake page on my page nav bar.
Basically, I want to create a 3 x 3 grid listing of thumbnails which link to that piece of work, how would I go about doing this? I don’t even know where to begin with this?!
Thanks in advance!
You probably want to define a size for post thumbnails for this side-bar area first. This needs to be registered with your theme so you can refer to it later one.
Then you can make use of the
get_the_post_thumbnail()
function passing the ID of the post as well as your post thumbnail size name as the second argument.Now the last thing you need to know is to get all posts of the category you like to get the thumbnails from. This can be done with a new
wp_query
just getting all categories posts.Then you combine this all together.
Example Code
This is some example code to display the thumbnails registered with the
sidebar-thumbnail
size. You need to do this generally with your theme, probably in the themes function.php. Please see codex how to do that. This little code takes care to query all thumbnails by category and then inserts a<br>
tag after every third thumbnail:It’s sample code so untested, but it probably helps you to get things running. All the functions used in there are documented in worpdress codex btw, so you can learn more about them there.