Easy Peasy Images
My last post, Post image the easy peasy way, got a great response including a few really interesting suggestions so I have expanded it a little and rolled it all up into a single file that can be included from within a theme’s functions.php file.
There’s a lot more code in this file than in the original function so I’m not going to explain it, I will just go through the additional content and the change to the usage of the function.
Ben Whitehouse suggested adding optional hyperlinks to the image. It is now possible to specify within the function whether the image should link to the post or not.
Tony Gray made some amendments to make the image expand using thickbox.
Including the image in the feed
Vivien asked about including the image in the feed. Included in the file is a hook that adds the image to the beginning of the content automatically. To do this I had to amend the function to make echoing the content optional so you can retrieve the image instead.
The image included is a thumbnail. You can change it by amending the function:add_image_to_feed
More post sizes
Cubus suggested using the Tim Thumb image resizing script. I haven’t used it here because I wanted to simply use the built in functions, but I wanted to highlight it as it is a great idea.
Default images by category
Jeff asked about default images, specifically if it was possible to assign default images to each category. It is, and now you can.
Included in the file is some extra functions that add a list of categories to the media browser so that you can assign images to one or more categories. If the function doesn’t find a post attachment with a sort order of 0 then it will default to the image attached to the category the post is in. Note: it will use the first category image it finds.
There is still only one function that matters and that is the template tag, shown below:
//in the example video the single post page uses:
Every argument within the function has a default. They are as follows:
- Size — medium
- Class — blank
- link to post — false
- link using thickbox — false
- echo result — true
Here is a quick example of the functions in use: