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 title showing space?
no comment on page 1371

Wordpress fun?
one comment on page 1376

Live blogging plugin?
4 comments on page 1258

Wordpress 3 admin speed up?
4 comments on page 1321

Framework photoshop?
3 comments on page 296

Fun wp plugins?
one comment on page 1376

Habari vs wordpress?
12 comments on page 440

Wp tags vs categories?
12 comments on page 7

Wordpress rss seo?
one comment on page 1361

Photo albums html5?
6 comments on page 1305

Wordpress chat?
no comment on page 1308

Wordpress exif data?
12 comments on page 230

Css sidear tab?
2 comments on page 336

Wordpress theme html5 blueprint?
6 comments on page 1305

Wordpress shortcode in plugin?
no comment on page 236

Html 50 photo album?
6 comments on page 1305

Get the post attachement?
24 comments on page 1065

Wordpress plugin development 30?
one comment on page 1373

Wordpress plugin development 30?
one comment on page 1373

Disqus formatting?
7 comments on page 1175

Html5 photoalbum?
6 comments on page 1305

Html5 photoalbum?
6 comments on page 1305

Wordpress fun?
one comment on page 1376

Fun wordpress plugins?
one comment on page 1376

Url shortener ideas?
4 comments on page 1190

Url shortener ideas?
4 comments on page 1190

Html 5 photo gallery?
6 comments on page 1305

Multiple post navigation?
no comment on page 1147

Html5 photo galleries?
6 comments on page 1305

Adding images to a wordpress 3 post?
24 comments on page 1065

Html5 photo gallery code?
6 comments on page 1305

Wordpress multiple blog master?
one comment on page 1376

Wordpress 3 tableprefix?
2 comments on page 1374

Wordpress 3 tableprefix?
one comment on page 1376

Using wordpress as a framework?
2 comments on page 335

Single post image size?
24 comments on page 1065

Get featured image src wordpress?
24 comments on page 1065

Disqus wordpress mu?
7 comments on page 1175

Image gallery html 5?
6 comments on page 1305

Wordpress theimage?
24 comments on page 1065

Wpgetattachmentimagesrc size?
24 comments on page 1065
  every 1743s, 1s ago, in 0.03s.
 __
(__)
   `
 kathy

I just tried the Commune theme which uses Easy Peasy on WP3.0 and I can no longer get the default category images to display.

 __
(__)
   `
 shag

Is there a (fairly painless) way to show all images attached to a post? I see your comment that this is a replacement for the custom fields and not the gallery shortcode but I’m wondering if you could push me in the right direction to figuring out how to display all images attached to a post. I’ve been hacking at your code but with no luck. Any help would be greatly appreciated.

thanks, Shag

 __
(__)
   `
 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?

 __
(__)
   `
 Michael Oeser

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

 __
(__)
   `
 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…

 __
(__)
   `
 admin

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

 __
(__)
   `
 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.

 __
(__)
   `
 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

 __
(__)
   `
 Rahman

Nice. Thank you!

 __
(__)
   `
 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...

 __
(__)
   `
 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

 __
(__)
   `
 tom (dB)

you do that in your wordpress settings under Geberal > Media

 __
(__)
   `
 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.

 __
(__)
   `
 Danno

Nice. Thanks!

 __
(__)
   `
 WordPress: Anteprime di immagini per i nostri Articoli

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

 __
(__)
   `
 Andrew Rickmann

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

 __
(__)
   `
 tonygray216

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

 __
(__)
   `
 Michael

I have a similar script running on wpengineer.com.For the default images i use a handwritten array. Your idea with saving the default images in the options is better.
One idea:
Allow more images to a category and use something like array_shuffle to select a random image .

Thank you,
Micha

 __
(__)
   `
 inspirationbit

Thanks a lot for updating the code with so many helpful changes. I just replied to your comment on the previous post and then saw your tweet about the updates. The video was helpful too. Great job, Andrew!

 __
(__)
   `
 Post image the easy peasy way – WP FUN

[...] NewerEasy Peasy Images Suggestion Roundup10 01 09 – 0 Comments [...]


0.02s