How to display Thumbnail in the block instead of Teaser?
Marat - October 21, 2008 - 06:17
| Project: | Similar By Terms |
| Version: | 5.x-1.15 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
| Issue tags: | image display |
Jump to:
Description
Hi everyone,
I am wondering if there is a way to display node thumbnail in the similar entries block instead of Teaser?
Thank you

#1
By default no but you can modify the .tpl.php file and make it happen pretty easily.
Thanks
Robert
#2
Thank you very much for your replay.
I have changed this
<?php}
if ($display_options == 'teaser') {
foreach ($items as $node) {
print '<li>'. l($node->title, 'node/'. $node->nid);
print ' - '. $node->teaser;
print "</li>\n";
?>
to this
<?php}
if ($display_options == 'teaser') {
foreach ($items as $node) {
print '<li>'. l($node->title, 'node/'. $node->nid);
print ' - '. $node->field_thumbnail; //replace teaser with field_thumbnail
print "</li>\n";
?>
but it does not work with me, any suggestions will be much appreciated.
#3
Check out this link http://drupal.org/node/134086 . It might help it is for 5.1 but it might work. Also you might want for a test to print_r out the node list to confirm that $node->field_thumbnail exists.
Thanks
Robert
#4
Thanks Robert, I couldn't find the link on Could you please have a look?
#5
That is weird it was there when I posted it reply. I updated to include the link and here it is again. http://drupal.org/node/134086
Thanks
Robert
#6
Thank you very much @rmiddle, this is very helpful. I will try to make it through imagecache.
#7
No updated in over a month. This issue is outside the core design of the module. I am going to mark it fixed.
#8
Hello,
I would also like to show thumbnails generated by imagecache instead of node titles.
Has anyone figured out how to do that with D6? I tried to use
$items_ls[] = l($node->field_squarethumbnail[0]['filepath'], 'node/'. $node->nid);
instead of
$items_ls[] = l($node->title, 'node/'. $node->nid);
in the similarterms.tpl.pho
but that didn't work.
Can anybody help?
Thanks!!
Roger
#9
I though imagecache put it images in images/ not node/ are you certain the file it is looking for is in files/node/ ?
Thanks
Robert
#10
Hi Robert,
I checked the path of a thumbnail. It is:
/sites/default/files/imagecache/squaretumbnail/"username"/
where "username" is the username of the node author.
Could you tell me how the code to print a thumbnail should look like? That would be great!
Cheers,
Roger
#11
Do you have devel module installed on this site? Can you insert the following line.
print '<li>'. l($node->title, 'node/'. $node->nid);print ' - '. $node->field_thumbnail; //replace teaser with field_thumbnail
print_r($node);
print "</li>\n";
and copy the large about of output this produces. That way I can see what is inside the array and figure out what you are getting.
Thanks
Robert
#12
Hello Robert,
I don't have the devel module installed. But if that's something critical I should do in order for you to find out the correct code line I could install the module.
I added the code you indicated to similarterms.tpl.php. The output (the part that includes the thumbnail) is:
[field_albumimage] => Array ( [0] => Array ( [fid] => 192 [list] => 1 [data] => Array ( ) [uid] => 1 [filename] => flight helmet.jpg [filepath] => sites/default/files/album/1/flight helmet.jpg [filemime] => image/jpeg [filesize] => 148394 [status] => 1 [timestamp] => 1230459680 ) ) [path] => content/luftwaffe-flight-gear [simple_access_owner] => Array ( [sa_view] => 0 [sa_update] => 0 [sa_delete] => 0 ) [simple_access] => Array ( ) [tags] => [last_comment_timestamp] => 1230737055 [last_comment_name] => [comment_count] => 2 [taxonomy] => Array ( [67] => stdClass Object ( [tid] => 67 [vid] => 9 [name] => WWII 1939-45 [description] => [weight] => 5 ) [74] => stdClass Object ( [tid] => 74 [vid] => 10 [name] => Germany [description] => [weight] => 6 ) [89] => stdClass Object ( [tid] => 89 [vid] => 11 [name] => Air Force [description] => [weight] => 0 ) [134] => stdClass Object ( [tid] => 134 [vid] => 13 [name] => Flight Gear [description] => [weight] => 5 ) ) [files] => Array ( ) )
Does that help?
Thank you!
Roger
#13
Try this code and let me know it output.
<?php}
if ($display_options == 'teaser') {
foreach ($items as $node) {
$image = '<img src="'. $node->field_thumbnail[0][filepath] .'" alt="'. $node->title . '" />';
print '<li>'. l($image, 'node/'. $node->nid, 'html' => TRUE);
print "</li>\n";
?>
Thanks
Robert
#14
Hi Robert,
Thank you for the code.
I got a blank page when I added this code. Is there something wrong with the { or }? It looks to me as if one is missing.
Thanks
Roger
#15
Roger,
Likely I haven't tested any of this code so a simple mistake like that is very doable. After looking at you previous code I made a new version that is less complicated and I think will do what you were tiring to get done.
<?php}
if ($display_options == 'teaser') {
foreach ($items as $node) {
print '<li>'. l($node->title, 'node/'. $node->nid);
print ' - '.'<img src="'. $node->field_thumbnail[0][filepath] .'" />' ; //replace teaser with field_thumbnail
print "</li>\n";
?>
Thanks
Robert
#16
Hi Robert,
I tried to add the code but unfortunately it still didn't work. At least there wasn't a blank page anymore. But the '-' were followed by just an empty space. No pictures.
I tried to change the code from 'thumbnail' to 'squarethumbnail' (that's how I call the thumbnails in imagecache). But still no pictures.
I saw variations of [filepath] as ['filepath'] and tried this as well. But still no luck.
Could the problem be with the filepath. Do I have to change the filepath in Image Cache so that it shows correctly?
Thank you for your patience. I hope you can find a working solution as I am sure many other people would like to use this feature as well.
Thanks
Roger
#17
PS: I checked the source code of the page and where the correct image path should be is:
So somehow the
"'. $node->field_thumbnail[0][filepath] .'"
doesn't work properly. I hope that helps.
Cheers,
Roger
#18
Militopedia,
I pull $node->field_thumbnail[0][filepath] directly from the array you posted. Try this.
<?php}
if ($display_options == 'teaser') {
foreach ($items as $node) {
print '<li>'. l($node->title, 'node/'. $node->nid);
// print ' - '.'<img src="'. $node->field_thumbnail[0][filepath] .'" />' ; //replace teaser with field_thumbnail
print $node->field_thumbnail[0][filepath];
print "</li>\n";
?>
And confirm the output is the path to the file you want to display as an image.
Thanks
Robert
#19
#20
Hello Robert,
I have tried but there was no output at all after the node titles. I tried several different variations (e.g. squarethumbnail instead of thumbnail, 'filename' instead of filename, different code, etc.) but no luck.
I have copied the source code of a views block that shows thumbnails of the latest added nodes. Perhaps this helps?:
<\code>
Apart from the code you have given me I tried the following:
$node['field_thumbnail'][0]['filename'] --> did not work, error
theme('imagecache', 'thumbnail', $node->field_thumbnail[0]['filepath']); --> no blank page, but no output
I am lost. What am I doing wrong?
Thanks,
Roger
#21
OK replace print $node->field_thumbnail[0][filepath];
with
print_r($node->field_thumbnail[0][filepath]);
print_r($node->field_thumbnail[0]);
print_r($node->field_thumbnail);
#22
Hello Robert,
I tried it but there was no output whatsoever. I added an extra text print statement just to test if the changes to the file were successful. The text output was visible but unfortunately no output was generated by the 3 code lines you indicated. Where could be the mistake? What would you need more from me to tell what the problem is? I could send you the sitename via PM if you like (the site is not finished yet and I don't want to make it public yet).
Thanks,
Roger
#23
PS: When I replace 'thumbnail' with albumimage (the name of the CCK field of which image assist generates a thumbnail called squarethumbnail) a path is given but to the original size image:
e.g.
http://sitename/sites/default/files/album/1/Bokelmann1.jpg
where the thumbnails are stored under
http://sitename/sites/default/files/imagecache/squaretumbnail/TestUser/1...
So it seems to me that the field 'thumbnail' is not recognized ?!
The original post (see below) didn't mention field_thumbnail but only field_albumimage (on first line). Are you sure that I should use field_thumbnail?
[field_albumimage] => Array ( [0] => Array ( [fid] => 192 [list] => 1 [data] => Array ( ) [uid] => 1 [filename] => flight helmet.jpg [filepath] => sites/default/files/album/1/flight helmet.jpg [filemime] => image/jpeg [filesize] => 148394 [status] => 1 [timestamp] => 1230459680 ) ) [path] => content/luftwaffe-flight-gear [simple_access_owner] => Array ( [sa_view] => 0 [sa_update] => 0 [sa_delete] => 0 ) [simple_access] => Array ( ) [tags] => [last_comment_timestamp] => 1230737055 [last_comment_name] => [comment_count] => 2 [taxonomy] => Array ( [67] => stdClass Object ( [tid] => 67 [vid] => 9 [name] => WWII 1939-45 [description] => [weight] => 5 ) [74] => stdClass Object ( [tid] => 74 [vid] => 10 [name] => Germany [description] => [weight] => 6 ) [89] => stdClass Object ( [tid] => 89 [vid] => 11 [name] => Air Force [description] => [weight] => 0 ) [134] => stdClass Object ( [tid] => 134 [vid] => 13 [name] => Flight Gear [description] => [weight] => 5 ) ) [files] => Array ( ) )
Thanks
Roger
#24
I found the solution!!!!!!!!!!
The correct code is:
print theme('imagecache', 'squaretumbnail', $node->field_albumimage[0][filepath]);
So it was albumimage rather than thumbnail and I used the theme function.
But thank you for your time. Without your continuous support I wouldn't have tried it so far and would have given up. That saved my day. Now for a beer ;-)
Cheers,
Roger
#25
Oh, I think I was too quick with the beer... :-( While the thumbnails are shown now, the problem is that always exactly the same 4 thumbnails are shown independent of the taxonomy of the current node. Even if the tags are completely different of the current node the same 4 thumbnails are shown.
HELP, I thought I did it.....
But the mistake could be my fault. I have 5 different vocabularies assigned to the node. None of them is a free tagging vocabulary and node of them is called 'Tags'. The help file of the module states that one should create a free tagging vocabulary called Tags.
Would it also be possible to use this module with the 5 non-free-tagging vocabularies instead? One is e.g. called period, one country, one branch of service, etc.
Thanks,
Roger
#26
Sorry about that. I re-looked and you are right it should be $node->field_albumimage[0]['filepath'].
When all else fails print_r your data in this case $node->field_albumimage[0]['filepath'] and see what it outputs.
No I have zero tags called tags. And it no longer only creates blocks for free tagging taxo types. But the images you are garbing are not images for taxo terms but images related to the nodes themselves. So if you have an image attached to node/51 and node/51 is one of the items on the list it will give you a thumbnail of the image attached to node/51. Are you using taxo Image modules to attach images to taxo terms and you want to display images based on taxo terms used?
Thanks
Robert
#27
Robert,
Thanks for the advice regarding the print_r. That's very good to know.
Regarding the tags I am confused. I thought that the module shows nodes that have most terms in common with the currently viewed at node? That's what I would like to achieve. Something like at youtube where you always get a suggestion of related videos (just pictures in my case) based either on terms or on the content itself.
I have the block 'Similar entries from ANY vocabulary.' activated. Shouldn't it show thumbnails of similar nodes that have tags in common with the currently looked at node?
I create one thumbnail per node. So every node just has one and instead of showing titles in the 'Similar entries...' block I would like to show these thumbnails instead. What did I do wrong that now always the same thumbnails are shown no matter at what node I am looking at?
Thanks,
Roger
#28
Hi Robert,
I think it may actually work as expected. Since it is still a test site I don't have much content and I think that's the reason why always the same thumbnails were shown. I have added two nodes with tags I haven't used so far and the block indeed showed for both nodes the other node that has exactly the same tags :-) If so, I am sorry, my mistake, I should have checked the output more carefully before ringing the alarm bell.
Now all I have to add is adding a hyperlink to the thumbnails. Perhaps it's an easy task but I'll see. If I find out how to do it I will post it here.
Thanks!
Roger
#29
Robert,
The following code generates a thumbnail with a hyperlink to the corresponding node. However, it doesn't use the imagecache thumbnail but scales the original image to 107x78. Hence, this is a very slow and resource intensive process.
print '<a href="/node/'. $node->nid.'"><img height="78" width="107" title="" alt="Similar posts" src="/'.$node->field_albumimage[0][filepath].'"></a>';I tried a bit further and found the solution I was after:
print '<a href="/node/'. $node->nid.'"><img height="78" width="107" title="" alt="" '.theme('imagecache', 'squaretumbnail', $node->field_albumimage[0][filepath]).'</a>';That may be something to consider as a new feature for your excellent module. Thanks for all your support!
Roger
#30
Roger Maybe. I am more likely going to take the final solution and write it up in the document for a drop in replacement. The is lots of code I would have to add to allow this to work inside the man module.
Thanks
Robert
PS. Glad you were able to get what you wanted.
#31
Aftering reading your discussion, and checking out http://drupal.org/node/134086
I have worked out on my site which running 5.x1.15!!!
Here's how I concluded
1) I have a CCK image field called "pho"
2) I set a imagecache called "box"
3) In the similarterm module, add the codes into the function
function theme_similarterms($display_options, $items) {
$output = "";
if (!empty($items)) {
$output .= "
\n";- '. l($item->title, 'node/'. $item->nid);
foreach ($items as $item) {
$output .= '
if ($display_options == 'teaser') {
$output .= ' - '. $item->teaser;
// start adding these codes
$nodep = node_load($item->nid);
$output .= l($nodep->title, 'node/'.$nodep->nid);
$output .= theme('imagecache', 'box', $nodep->field_pho[0]['filepath']);
$output .= check_markup($nodep->teaser, $nodep->format, FALSE);
$output .= '';
//end adding these codes
}
$output .= "
\n";
}
$output .= "
\n";
}
return $output;
}
#32
sunumen,
Important note. I pass the full node to the theme function in 5 and the .tpl.php file in 6. There is no reason to reload the node info.
Thanks
Robert
#33
I am thinking about ways to use this I am just not seeing a way to use other then to add a document pages for people to use.
Thanks
Robert