I've been trying to get images to appear on my sidebar using the method outlined here:
http://drupal.org/node/180852
It's not working and no one seems to be able to offer support on this, so I'm trying to make this work on my own.
I have a new content type which is sidebar_images. I added, as an example, 5 different sidebar_images. I also added a new CCK field for my page nodes which asks which sidebar_image to attach. So all the pages in my site have a sidebar_image attached to them.
I have a block view on the right sidebar that I want to display whatever image is attached to the current page. Problem is, I don't seem to be able to figure out what page I'm on from the block view functions.
Does anyone know a way for me to access information about the current page FROM my special block view function? function phptemplate_views_view_list_sidebar_image($view, $nodes, $type)
Or if you know a better way to go about this that'd be good too. Thanks! :-)
Comments
...
A theming function is used for theming something. "Something", in our case, is the sidebar_image node. This node is picked before it's handed to this theming function. So there's no reason, in this late theming stage, to poke around the page.
Note that this article has one piece of code, which deals with the same question you raise. That code finds out what node the user is viewing, fetches it, sees what sidebar_image it references, and makes the view pick only this node.
"Note that this article has
"Note that this article has one piece of code, which deals with the same question you raise."
I figured thats what this code was doing, but it's not working. Any thoughts on why it may not be working? Is there anyway I can echo or print some things from this argument code to see more exactly what information it has? If I just put a print statement in there it doesn't show up.
...
When something doesn't work, first try something simpler.
Instead of the complicated code on that page, use a simple:
This will restrict the view to show only node #52 (which is of a 'sidebar_images' type. Of course, change this number to something that exists on your system.)
If that doesn't work, you know that you missed something very basic.
When I do this, the image
When I do this, the image that's the default image appears. I guess that's good news? I'm still not sure how else I can troubleshoot this without printing something...
...
Patience. We'll get to that ;-) You aren't very helpful:
Don't know what's a 'deault image'. I'll take your word that it's "good news".
Now,
Instead of hardcoding '52', do:
(I hope I didn't make a typo somewhere.)
Sorry Im not helpful! :( I
Sorry Im not helpful! :( I dont know what information is important! I dont know what a default image is either, but apparently Drupal has assigned one of the images I've uploaded as a default, so its still not pulling the image for the specific page, it's just grabbing a default. I know this because before when I just made the arg[0] = 8, this image appeared on the right. I looked at the source and saw the image that was being displayed was from files/default_image/ or something like that :-)
And unfortunately, when I put this code in, nothing appears in the sidebar. It's blank !
Here's an example.
http://olgs.clientmark.com/welcome/philosophy
This is node 8. It has a sidebar image assigned to it called Philosophy. The nid for that image is 53.
I'd attach some screenshots for you but looks like only the original poster can.. hmm..
...
Perhaps you included the "<?php ... ?>" tags in the code you pasted? You shouldn't (normally I omit them form code I type here, but this time I did that to get syntax-check.)
It's helpful to type some messgae in the 'Empty text' box of the view. This way we can distinguish between "the view works but shows no nodes" (if the message is shown) and "view does not work".
Hey, I wrote the "patience" thing in humor ;-)
You got me !! I had the php
You got me !! I had the php tags in there.
I took them out and now the entire site is broken :-) (White Screen of Death)
Okay I fixed it.
Okay I fixed it.
Using your code now I get the default image again/still.
Messages:
* We're viewing node 'Philosophy'
* This node doesn't have an associated image-node
...
How did you name the field that points at the 'sidebar_images' node? I suspect you didn't name it 'side_block'.
If you don't know the answer, add the line:
Put it after the line "drupal_set_message('This node doens't have' ...".
You'll see a bunch of text. Pate it to http://pastebin.com/ (so I can see it, later), and then remove that line (so it doesn't "ruin" your nice pages).
You're right again, I named
You're right again, I named them side_image.
I've fixed your code accordingly and now it seems to see the image number!!!! We're getting somewhere! :-)
IT WORKS!!!!!!!!!!!!!! IT
IT WORKS!!!!!!!!!!!!!! IT WORKS!!!
Thank you soo so soo much :-)
...
:-)
Now that you know what the problem was you can revert to the original, the article's, code (after modifying it), but you don't have to.
(Note that my code contains a "$args[0] = 52" fall-back line. It means that an image will always be shown, even if the main node doesn't point to any 'sidebar_images'. If you want no fall back image, remove that line and change the 'Node: ID' argument setting to show nothing when there's no argument.)