Hi all,
I started Drupal only a few weeks ago, so my understanding of it is still quite limited.
I am trying to put a block containing images above the content on my teaser page (eventually they'll be manipulated to do a slideshow).
So I have this put into my block:
print theme('imagecache', 'w300xh172', $node->field_headline_image[0]['filepath']);
The images don't show. Uncommenting print_r($node) shows that they ARE being loaded on the page. Using return instead of print breaks my page, a previously mentioned solution. Putting this code on in the node tpl itself does generate the images, but its not what I want.
Interestingly enough, the output of what's inside the slideshow div shows one image with the src being the directory rather than the files(s) like so: (src="http://localhost/sites/default/files/imagecache/w300xh172/")
I am assuming my problem is that the php code as it is now cannot be run successfully because it's being called from a block.
I am sure the answer is on this site somewhere, but I've been looking for a few days now with few answers. Any help with this is appreciated!
Comments
Comment #1
nvl.sateesh commentedi am assuming that you did a $node = node_load(array('nid'=>$nid)) function inside your block
with that assumption, first i would suggest you just print the $node->field_headline_image[0]['filepath'] variable from the block. this should tell if it is actually getting loaded.
if it is indeed showing you the filepath, then, print it using a img tag directly without imagecache just to see what happens.
i am assuming that the print_r($node) shows the image because it is being called on the teaser page where the $node variable is already being loaded due to the teaser.
Comment #2
jfama commentedThank you for your quick response Sateesh,
I was not familiar with the first code. However, it still doesnt seem to work.
I realized that the print_r didn't actually show that the image was loading. Trying to print $node->field_headline_image[0]['filepath'] didn't show any results either. Coding in just a static image worked.
I have:
$node = node_load(array('nid'=>$nid)); print theme('imagecache', 'w300xh172', $node->field_headline_image[0]['filepath']);Did I code the previous correctly? If so, then maybe there is something that must be modified elsewhere?
Comment #3
nvl.sateesh commentedwell, what is the $nid value? are you passing it to the node_load function? so lets assume your node id is 123, then
i am sure that you are missing the $nid value. or are you assuming that by placing the block in the teaser view page, it will also have access to the $node object?
Comment #4
jfama commentedSateesh,
Although inputing the $nid value does show the associated image (finally!) this isn't what I want to do. I want to call all the images of field_headline_image rather than just one specific value. (hence the eventual slideshow gallery)
Any ideas?
Comment #5
nvl.sateesh commentedWell, now at least you know how to get one image ... perhaps you will use this knowledge sometime in future...
regarding the slideshow...i would suggest you use this module. this does exactly what you want.
http://drupal.org/project/views_nivo_slider
this module allows you to create a view with all the images, and the render them into a slide show....
have fun :-)
Comment #6
jfama commentedThank you for the module, Sateesh.
However, my boss doesn't want to use DDB and Views unless he absolutely has to, so I must keep looking for a solution.
Lets try this again for whoever is out there. This code:
Shows perfect on my teaser page if it's put in my tpl file. However, because it repeats itself like all the other elements in the teaser, I have to input it in a block above the content. When I do this, the code is not processed. The input is set to PHP, and certain elements of the code are being put onto the page, just not all of it. The goal of this code is to output all the field_headline_image images with the w300xh172 preset.
My question is: How do I get this block to process correctly? Sateesh's node_load solution sounded right, but I cannot use it if it's only compatible in outputting one value only.
Comment #7
nvl.sateesh commentedok. first my assumptions:
1. I understand that you did not make any changes to your node.tpl.php file in your theme. This means that it is printing the core content using
2. If that is the case, when you try to load the node again, it will print twice since the image is already present in the content. So, alternate solution is to customize your node.tpl.php file as i have detailed in the link below:
http://drupal.org/node/864906#comment-3249496
3. I think you can use a function in your template.php file that will get all the images for one particular node and then use them as you want to display the slide show. If you do this, then, you cannot use print $content, but have to use custom fields such as $node->body etc... see link above.
post your code, and folder structure, with some screenshots and i will be able to help better...
Comment #8
nvl.sateesh commentedalso, you should note that the node_load can bring all the images you have attached with that node. for example, your image field allows 10 images to be uploaded per node. lets assume that your field name is "field_headline_image". then, you can do this to get all the images:
Comment #9
john.money commentedUnsure how this is related to Block Node visibility. If I am mistaken, please feel free to reopen.