CCK for Drupal 6 has an Image field and a Link field...but no ImageLink field?

sebsebseb123 - April 11, 2009 - 20:38

CCK for Drupal 6 has an Image field and a Link field...but no ImageLink field?

I'm pretty new to drupal but I've made a custom Content Type... It has 4 text fields, a URL field that opens a different page on a different site, and an Image field which I can't seem to turn into a hyperlink.

Is there really no ImageLink for drupal 6?

I know I could use Views.. but that seems overkill just to add some < a href > tags...

Any help?

In case you wanna see exactly what I'm talking about, you can visit my site http://www.sebastianlesch.com
In the portfolio, if you click on one of the sites then it takes you to a WebSite Profile page that has 2 screenshots of the site, and a description, URL link, ect... I want the screenshot images to be links.

Thanks

=-=

VeryMisunderstood - April 11, 2009 - 20:41

if you want images to be links :

go to administer -> content types
edit the content type in question
click on the display fields tab
set as you desire (ex: image linked to node or image linked to file)

...yeah, except I want the

sebsebseb123 - April 11, 2009 - 20:46

...yeah, except I want the image to link to an external site.

=-=

VeryMisunderstood - April 11, 2009 - 20:49

as far as I can see, you can't do that.

....yeah, that's why I'm

sebsebseb123 - April 11, 2009 - 21:03

....yeah, that's why I'm posting this... It seems strange that I can't turn an Image into a link.

Maybe I'm just missing something?

=-=

VeryMisunderstood - April 11, 2009 - 21:05

you can turn it into a link.
To be clear, what you want is to embed an external that may or may have nothing to do with the image uploaded through a CCK field.

"embed an external"? an

sebsebseb123 - April 12, 2009 - 04:27

"embed an external"?

an external what?

Could you be a little clearer?

So... is it possible to turn an image into an external link? Would I have to mod the module? Insert custom PHP code? Am I alone in thinking that it should be easier to create an image that links to an external site?

Thanks, btw

i think he meant..

calshei1 - April 12, 2009 - 14:41

I think he meant "embed an external link". And I'd like to know how to do that through the cck/view field as well.

node-type.tpl.php

gbrussel - April 12, 2009 - 14:59

If you feel comfortable modifying the node template file, you can always do something similar to this.

1) Copy the node.tpl.php and rename it to node-yourcontenttype.tpl.php
2) Open node-yourcontenttype.tpl.php and insert these lines where you'd like them to show up in your node:

<?php
 
print '<a href="' . $node->field_your_url_field_here[0]['value'] . '">' . $node->field_your_image_field_here[0]['value'] . '</a>';
?>

3) This will print out the image wrapped in an anchor link to your external URL.
4) If you do it this way, make sure in display fields you've marked these two fields as "Exclude from display", otherwise you'd duplicate it.

YES!!!!! Thank you so much.

sebsebseb123 - April 12, 2009 - 20:31

YES!!!!!

Thank you so much. It works now. AND I now know how to make custom templates for a content type!

Thanks again.

I'm jealous...

zeta1600 - April 15, 2009 - 21:17

seb123... sounds like you got this to work... would you mind sharing exactly what you did? Did you have to add a link field? I'm not sure how to begin. I need to do exactly this... add an image field and link it to an external page.

I'm a noob... so the more childlike you can explain the better...

Local:
Mac OS 10.5.5
Firefox 3.0.5

Server:
Apache 2.0.63
PHP 5.2.5
MySQL 5.0.51a-community

=-=

VeryMisunderstood - April 15, 2009 - 21:44

did you even try this?

http://drupal.org/node/431088#comment-1466710

I don't know how much more childlike the isntructions could be, if you explain what you are stuck on with regards to the steps you can be better helped.

That's what I'm asking

zeta1600 - April 15, 2009 - 22:01

That's what I'm asking about... I've added two new fields, 1 for an image field and another for the link... I've used those field names in the code given above in a duplicate of the node-mycontenttype.tpl.php. I then uploaded that file into the my theme folder. And, I seem to get it to work.

So, to answer your question... Yes, I tried it. Probably incorrectly, but yes, I did.

Thanks for your consideration to help VeryMisunderstood.

Local:
Mac OS 10.5.5
Firefox 3.0.5

Server:
Apache 2.0.63
PHP 5.2.5
MySQL 5.0.51a-community

What did you name your fields

gbrussel - April 15, 2009 - 22:10

What did you name your fields when you created the content type? That's what you should use in the code. So when you see $node->field_your_url_field[0]['value'], replace 'your_url_field' with the name you entered on creation. So if I create a URL field and call it "url", then in the code I'd call $node->field_url[0]['value']. The names must match up or it won't find the field you created.

Thanks for your response

zeta1600 - April 15, 2009 - 22:16

Thanks for your response gbrussel... The names of my fields are as follows:
Text field for the link: field_lev_buy_linkto
Image field for the image: field_lev_button
here is my current code...

<?php
 
print '<a href="' . $node->field_lev_buy_linkto[0]['value'] . '">' . $node->field_lev_button[0]['value'] . '</a>';
?>

1) Should I dup the node.tpl.php from my current theme? Or the core template?
2) I don't know where in the node-mycontenttype.tpl.php I should insert the code above?

Local:
Mac OS 10.5.5
Firefox 3.0.5

Server:
Apache 2.0.63
PHP 5.2.5
MySQL 5.0.51a-community

Yes. Clone the node.tpl.php,

gbrussel - April 16, 2009 - 02:16

Yes. Clone the node.tpl.php, and rename it node-contenttypename.tpl.php. So if your content type is called "test", then you'd name it node-test.tpl.php. You'll have to clear your theme's registry for it to see the new template file, but this is as easy as going to Admin > Build > Themes and pressing the save button.

As for where in the file to place that code, that's up to you and how you want to lay out your page. By default the node.tpl.php will spit out something like <?php print $content; ?>, so you may want to use this "field by field" printing method on all your CCK fields. To find all the fields, simply put a <?php print_r($node) ?> to get all the available content pieces, and print them out one by one in whatever HTML objects you want.

Keep in mind that each piece you print you'll have to then "exclude" on the content type's "Display Fields" settings page. Hope this helps, and doesn't confuse you further.

I don't believe it... I still

zeta1600 - April 16, 2009 - 14:05

I don't believe it... I still can't get this to work. I've tried switching the theme to garland and re-did step by step, I've tried putting the custom fields to another content type, and checked the permissions... I have no problem seeing the custom fields on the content type, but I'm not seeing the second image generated from the new-mycontent-type.tpl.php. It's got to be a really easy thing that I'm missing. Any ideas?

Local:
Mac OS 10.5.5
Firefox 3.0.5

Server:
Apache 2.0.63
PHP 5.2.5
MySQL 5.0.51a-community

If you're printing multiples

gbrussel - April 16, 2009 - 15:57

If you're printing multiples of that field, you'll have to change the number.

First image: <?php print $node->field_theimage[0]['view']; ?>
Second image: <?php print $node->field_theimage[1]['view']; ?>
Third image: <?php print $node->field_theimage[2]['view']; ?>

And so on...

Thanks again gbrussel... it

zeta1600 - April 18, 2009 - 05:37

Thanks again gbrussel... it wasn't the multiple field. Anyway, now I'm getting text link "Array" I don't know where that's coming from.

Local:
Mac OS 10.5.5
Firefox 3.0.5

Server:
Apache 2.0.63
PHP 5.2.5
MySQL 5.0.51a-community

Link field has to be a text field

glennr - June 23, 2009 - 06:17

I realise this is a couple of months after the fact, but if you or anyone else is still having a problem, don't be tempted to use the CCK Link module to create this link field. I foolishly tried it before realising my mistake. The link field has to be a plain text field.

Can't get it to work

webnation - April 21, 2009 - 10:07

Hi,

I've gone through the steps in http://drupal.org/node/431088#comment-1466710 and it doesn't seem to work.

In the source code I can only see where the image and link should be.

I'd be really grateful for any thoughts - this would be brilliant if I could get it to work.

Thanks

=-=

VeryMisunderstood - April 21, 2009 - 13:49

please elaborate on:

In the source code I can only see where the image and link should be.

Are you stating that the code is now correct when you view your rendered pages source code or that it is incorrect?

If the rendered page isn't picking up your changes to the tpl.php file you may have to clear the theme registry by going to administer -> themes and re-saving the form.

Sorry - I should have been

webnation - April 22, 2009 - 06:37

Sorry - I should have been clearer.

I created a content type called 'flags', added fields 'field_flag_link' and 'field_flag_image'. I then created node-flags.tpl.php and added the code

<div class="content1">
   <?php
 
print '<a href="' . $node->field_flag_link[0]['value'] . '">' . $node->field_flag_image[0]['value'] . '</a>';
?>

</div>

I then created a node using content type 'flags' with an image and a link but only the original image with the link next to it shows up on the page.

However the source code includes the <div class="content1"> I added in node-flags.tpl.php but only contains <a href=""></a> as shown below.

<div class="field field-type-filefield field-field-flag-image">
    <div class="field-items">
            <div class="field-item odd">
                    <img  class="imagefield imagefield-field_flag_image" width="150" height="160" alt="" src="http://localhost/londonhotel4/sites/default/files/hat_1.jpg?1240310738" />        </div>
        </div>
</div>
<div class="field field-type-link field-field-flag-link">
    <div class="field-items">
            <div class="field-item odd">
                    <a href="/londonhotel4/content/summer-city">http://localhost/londonhotel4/content/summer-city</a>        </div>

        </div>
</div>
    </div>
<div class="content1">
   <a href=""></a></div>

So it does seem to be picking up the changes in the new tpl.php file - sort of. I did re-save the theme.

Thanks for replying.

Good tip. Thanks!

dzepol - April 15, 2009 - 23:44

Good tip. Thanks!

-D

What in the world am I

zeta1600 - April 16, 2009 - 01:33

What in the world am I missing?

Local:
Mac OS 10.5.5
Firefox 3.0.5

Server:
Apache 2.0.63
PHP 5.2.5
MySQL 5.0.51a-community

Here is how I did it and

etcetera9 - April 25, 2009 - 15:07

Here is how I did it and works for me:

I have 2 fields named: "link" and "image".

The important part is that I choose "URL as plain text" for Link field and "Image" for Image field from Display Fields tab of my content type. Also I exclude Link and Image form display. Then:

1) Copy the node.tpl.php and rename it to node-yourcontenttype.tpl.php
2) Open node-yourcontenttype.tpl.php and insert these lines where you'd like them to show up in your node:

<a target="_blank" href="<?php print $node->field_link[0]['view']; ?>"><?php print $node->field_image[0]['view']; ?></a>

You may also choose target as "_self" or something...

And then I go to admin>site building>themes and just Save Configuration for the theme read the new tpl.php file.

Hope it helps...

Sinan

Got it...

zeta1600 - May 2, 2009 - 04:35

For some reason... your code worked...

Local:
Mac OS 10.5.5
Firefox 3.0.5

Server:
Apache 2.0.63
PHP 5.2.5
MySQL 5.0.51a-community

Really drupal 6 doesn't have an imagelink field?

telemako - April 18, 2009 - 17:22

I need to create a view with the following fields:
an image | a description | a pdf_icon linking the a pdf stored on the website

I'm able to create a view with the first two column using VIEW+CCK.
Follow my step tell me where i miss to have what i need:
1) I create a new content type called product_list
2) I add an image filed
3) The is the missing feature i need : an image files able to have a link to a pdf stored with web filemanager

4) I create a view
5) I add to the view the field : content->imagefield
6) I add to the view the field : node->body (which has a description)
7) I cannot have the link to the file cause neither exist a cck field or a webfilemanager field with this ehavior

the only filde i can see in the list is the upload but is not what i need, i need to use a file that is yet present in the filemanager and i want use an image (pdf icon) to link it.
Please help

Plz let me trust in drupal and be sure I'm not wasting my time...
Here is the link to old site i need to improuve using drupal:
http://www.telecontrolli.it/eng/default-wproducts.html

Output this field as a link

etcetera9 - June 24, 2009 - 13:37

If you know the link of the file you can do something like this:

You are using an image field. In the settings of this filed there is this option: Output this field as a link

You can give a link to that image... And there is an option to use replacement patterns (like Token). You have to add a link filed below that image field..

Maybe you can try this approach...

Cheers,

Sinan

linkimagefield

keva - July 12, 2009 - 15:33

would the linkimagefield module accomplish what you need?

http://drupal.org/project/linkimagefield

 
 

Drupal is a registered trademark of Dries Buytaert.