I want to find an editor friendly way of adding image links to a block/region on my page-front.tpl. When I say 'editor friendly' I mean that s/he should be able to go though the standard 'create content' process and not have to jump through lots of extra/new hoops to create this new piece of content.

I've tried creating a new Link Image Field content type in CCK, picking it up in Views and then getting Views to produce a block. Unfortunately, it would seem that Views can't 'see' images from Link Image Field so they don't appear in the subsequent block

So I then thought about printing my CCK Link Image Fields directly into a Drupal custom block. This appears to be a bit tricky too. The following (adapted) bit of code (from http://drupal.org/node/260730) looks as though it might be helpful. But I can't quite grasp how I could apply it to my problem.

<?php
if ( arg(0) == 'node' && is_numeric(arg(1)) ) {
  $node = node_load(arg(1));
  print l(array(), $node->field_my_cck_link_image_field");
}
?>

I (think!) I understand that in order to reference my cck field from inside a block I have to load the node that the CCK field lives in - and that's what the above is doing. But putting this directly into my Page-front.tpl doesn't do anything.
Any ideas?

Thanks

Adam

p.s. accidentally posted this in CCK issues first.... am not deliberately cross posting.

Comments

i-sibbot’s picture

Image Link? If you mean and img tag wrapped with an a href tag then why not go back to using Views. This sounds like the solution you want. Also, where is the link, linking to. A larger version of the image wrapped in the link? or some other place entirely? If its the previous, then may i suggest looking into image and imagecache to generate thumbnail sized images and keep the larger parent.

scrimmage’s picture

Ta for that.

I'm trying to display a number of logos that when you click on them take you to external sites.

I did think of adding the URLs for each external link in the fields editing dialogue in Views (that's what you mean, right?) - that's ok for me but very fiddly for someone else (an editor) who hasn't used Views.

Ideally, this is the path I'd like the editor to follow when they decide that an additional logo is needed on the front page.

• Create Content/'Add or Remove Front Page Logos' (which is a form with CCK fields)
• Upload the new logo to a CCK field in the next page. Type in the external URL that goes with the logo into another field.
• Press save and the additional logo linked to the correct external URL appears on the front page.

That's what I was trying to do with a combination of CCK, Link Image Field and Views.

Adam

i-sibbot’s picture

Right. understood.

Create a new Content type, call it what you wil
In the creation page of that new Content type, go to the filed set "Submission Form Settings". Delete "Body" from the "Body field label" text field. This will remove the "Body" section for this content type.
Save

Then, add two new cck files. And image upload field and a plain text field. The latter will be used to input the URL you wish to link to. Save and create some examples

You now have your content you wish to target.

Views, create a view that target only the new content type, selec tthe two cck fields. On the image field, "output this field as a link" then look at the replacement patterns. Make usre the URL cck field is above the Image cck filed in the "Fields" section above. this will make it available in the patterns. Use the Arrow sort button to drag and dorp the fields order.

scrimmage’s picture

At first (rather inexpert) glance that looks just what I'm looking for. So I'm 'attaching' the image to its external URL in Views...cor, blimey guv - marvellous.

And then I can theme the contents of the block that Views produces using a Views template. Double marvellous.

I'll give it a go soon and let you know how I get on.

Adam

renenee’s picture

This was incredibly helpful for me, as well. Fantastic, clear instructions. Thank you!

MorganG’s picture

Nice, fantastic! Just what i was looking for! Thanks!

rrockafellow’s picture

i-sibbot, understood your solution to a point. Got that you create two cck's for the image and its url. Lost me when you refer to replacement patterns. Is their a views module that is needed to be able to specify a replacement pattern?

i-sibbot’s picture

"output this field as a link" then look at the "replacement patterns" option that this checkbox will make visible.

rrockafellow’s picture

Looking at some websites talking about output this field as a link, I see where "output this field as a link should show up" but in my drupal views it is not showing up for me.
As far as I can tell there are no permissions that would hide it from me. Its very odd and frustrating.

i-sibbot’s picture

Make sure all the views modules are installed and run the update.php page. If nothtin shows, then uncheck and reinstall views (microsoft approach :). If that doesnt work then look into creating a test view where you filter by Node Type, then pull the Title field as a field to display and see if there option is there. This would suggest there is something strange about the content you are trying to "output as link".

erik’s picture

I was looking exactly for that, great!
Thanks a lot for this simple insight :)

zirhc’s picture

Nice post... this helped me figure something out that was puzzling me. Thanks

ñull’s picture

Looks nice what you do but that doesn't solve the problem of imagecache. Looks like I have to go back to hacking my solution with a (php) custom field and finding out how to get the right image cache from a fid. Link Image Field does not provide any news in this area either. I'm disappointed.....