Ferodynamics Network

popular: profile privacy, mobile privacy

January 10, 2009

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.

New stuff

Hyperlinks

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.

Thickbox

Tony Gray made some amendments to make the image expand using thickbox.

Within the file, below, is a function that automatically queues up the thickbox javascript and css. You can then use the function to choose whether to link the image to the full-size version using thickbox.

If you aren’t going to use that you might want to comment out the following line from the class constructor so it doesn’t call the css and javascript:

[php]
add_action('wp_head', array(&$this,'enqueue_thickbox'),1);

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.

Using it

There is still only one function that matters and that is the template tag, shown below:

[php]

//in the example video the single post page uses:

Every argument within the function has a default. They are as follows:

Example video

Here is a quick example of the functions in use:

Download

You can download the post image code here. To use it include the file from inside the functions.php file, and insert the the_image tag inside the loop where you want the image to appear.

Wordpress Chat
one comment
page 1308
Html 5 Gallery
6 comments
page 1305
Html 5 Gallery
6 comments
page 1305
Silence Is Golden
3 comments
page 213
Questions About Habari For Wordpress Users
6 comments
page 424
Theming Habari Vs Wordpress
13 comments
page 440
My Experience Of Flexx
4 comments
page 1026
Plugin Update Fun With Photo Data 2
one comment
page 815
Post Image The Easy Peasy Way
26 comments
page 1065
Gaining Benefits From Plugins
8 comments
page 1167
Categories Vs Tags Either Neither Or Both
12 comments
page 7
Fun With Theme Widgets
24 comments
page 867
Beware Wp Cache
8 comments
page 1310
Six Million Ways To Die Choose One
14 comments
page 1128
Post Image The Easy Peasy Way
26 comments
page 1065
Post Image The Easy Peasy Way
26 comments
page 1065
Wordpress Chat
one comment
page 1308
Post Image The Easy Peasy Way
26 comments
page 1065
Beware Wp Cache
8 comments
page 1310
Wp Polls Reviewed
one comment
page 58
Wordpress Chat
one comment
page 1308
Fun With Photo Data
12 comments
page 330
Fun With Sidebar Tabs Styling
2 comments
page 336
Html 5 Gallery
6 comments
page 1305
Using Your Own Url Shortener
4 comments
page 1190
Html 5 Gallery
6 comments
page 1305
My Experience Of Flexx
4 comments
page 1026
Fun With Sidebar Tabs
193 comments
page 57
Html 5 Gallery
6 comments
page 1305
Fun With Plugins
27 comments
page 14
Wordpress 25 Exif Fields
12 comments
page 230
Html 5 Gallery
6 comments
page 1305
Html 5 Gallery
6 comments
page 1305
Html 5 Gallery
6 comments
page 1305
Quick N Dirty Replacement Text
no comment
page 122
Beware Wp Cache
8 comments
page 1310
Theming Habari Vs Wordpress
13 comments
page 440
Fun With Sidebar Tabs Styling
2 comments
page 336
  updated 1 seconds ago
Thursday, 12pm
Len

When I embed a photo in a post that has a category, I get a double posting of the image, one as the embedded image, one as the category image. But when I got to the media library, there is no category marked on the image. Why?

Thursday, 12am
Michael Oeser

Very useful functions but can you post the code which has to be inserted into the template again since it doesn

Tuesday, 10am
shawn

Is there a variable that I can use on my homepage to display the ‘default category image’?

I’m simply looking for a variable or something that I can use within the excerpt that will force show the default image even if an image shows in the article.

It’s for a kinda special project I am working on where I have the categories set to the authors names with the default picture being a photo of the author. I wanted to use that default author photo image in the widget.

thanks

btw
I don’t really understand how the comment system replies work. Am I reading from right to left, top down, etc…

Monday, 4pm
admin

Thanks Shawn for the alert. I’m uploading the files now.

Monday, 2pm
shawn

BTW… the link to the download for the code is broken. I already have it from a few weeks ago, but others can’t get to it now.

Monday, 2pm
shawn

Plugin works absolutely perfect!

I do have one question:

What would be the function for pulling the ‘default category image’ so that I can use that image only for the thumbnail on my homepage?

My homepage has small ‘excerpt’ boxes which show the latest posts with the thumbnail and a bit of text and readmore.

Instead of showing the article thumbnail on the homepage, I would like to replace the logic to show the image that is set as the category default if the article has no images.

Right now I use the following:

When there is no image in a post, it shows the category default. When there is an image in the post, it grabs that image instead.

I am trying to override that logic.

thanks

Tuesday, 1am
Rahman

Nice. Thank you!

Friday, 10am
Andrew Rickmann

Dan, the functions within the loop depend on the $post global variable being set. If it is set then the function should work. However, the usual way is to create a new loop containing the posts you want, and then use it as normal.

This page should help: http://codex.wordpress.org/The_Loop#Multiple_Lo...

Thursday, 9pm
danjothebanjo

Hi Andrew, this code looks like just the ticket for me. Being new to WordPress I've found it frustrating how “buried” all this access to post images is – and had no joy on the WP support forums.

How can I use your the-image tag outside of the loop? e.g. to display the first image attached to a specific post on my static homepage. I'm currently using a custom-field but I'd prefer to create a unique post to manage this image element on my homepage – it'll bjust be much easier for my non-techy client to manage!

Thanks for generously posting your code.

Dan

Thursday, 8am
tom (dB)

you do that in your wordpress settings under Geberal > Media

Thursday, 2am
Danno

Question if I may … how does one change the dimensions at which the images are displayed? I'm particularly interested in changing the dimensions of 'medium'.

Thanks in advance.

Thursday, 2am
Danno

Nice. Thanks!

Saturday, 6pm
WordPress: Anteprime di immagini per i nostri Articoli

[...] Easy Peasy Images Suggestion Roundup [...]

Friday, 9pm
Andrew Rickmann

No it will only show one. This is a replacement for the custom field technique not a replacement for the gallery shortcode.

Friday, 8pm
tonygray216

Will this show all images attached to a post? The code looks like it does but I'm only seeing the first one.