By tomski777 on
What code do I need to use in order to print a specific nodes content in a block i.e. node 16 - I've hunted & can't find a how to anywhere!
What code do I need to use in order to print a specific nodes content in a block i.e. node 16 - I've hunted & can't find a how to anywhere!
Comments
It depends on what you want to print
Given that you know the node id (nid), the following code will load the contents of a node.
If you want to print the complete formatted node then add this code after the call to node_load()
All thogther this would look like
use VIEWS
It's ofcourse also possible to use views to print node-content in a block. No coding involved and most likely, no extra modules.
Well...
If you want to use Views then you're talking about downloading CTools and Views and enabling four modules or so, then creating a view and noodling with the filters and finally noodling with the block visibility settings. Sure, it gives you finer control of the output but that's a lot of overhead if all you need is a quick thing.
A couple of the snippets on this page are pretty useful as is and don't require modules at all.
That's why I wrote: "most
That's why I wrote: "most likely". There might be other readers of these posts who have "views" also already enabled. It would have been a shame not to mention this possibility for those readers/
The filtering is not complicated, so for those interested:
Contextual filters » Content: Nid » When the filter value is NOT available » provide default value » Content-id From URLSomething Like this
Something Like this, in a custom PHP block.
Thanks
This also works perfectly in Drupal 6, btw.
Cheers for that....
works perfectly - I knew it would be simple in the end!
><>tomskii
><>www.mutinyarts.co.uk
What if you wanted to start
What if you wanted to start with a path alias instead of a node id?
Something like this should help
The following code coverts an alias to a 'normalized' path.
Since it is looking for nodes, it checks to see it the return path referes to a node.
For Drupal 7
I know this is an old node, but I found it when researching the topic 6 years later so others may as well.
For Drupal 7 the following will output the full node
However you can output individual fields like the body by drilling into the array as follows:
thanks! :)
thanks! :)
Thank you so much..
Thank you so much..
I have a question regarding
I have a question regarding accessing data within the $node object above.
Until I found this post, I was attempting to display node contents by accessing the information through $node->body. However, no matter what way I attempted to print the results, nothing would show up.
I tried drupal_render($node->body) and drupal_render(node_view($node->body));
Your method above worked, but that leads me to my question:
What exactly was I trying to access by using $node->body? I understand that node_view() outputs an array, and by using $nodeView['body'] you were able to access a position in said array. However, why didn't my method work?
Thanks
This is very handy for
This is very handy for reusing snippet code if you have defined 'snippet' as a content type.
what if i have path instead of nid
i have a page from custom module but its having path and not nid so how to go about it.
thanks,
ketki
You custom module would need
You custom module would need to also provide a block.
John, that's just what I
John, that's just what I needed.
Filter by number of characters
I have a solution for filter content by number of characters.
I hope it will be useful.
Regards.
Note this solution also
Note this solution also removes any html markup.
Bummer
Is there any tweak that would preserve markup?
Try the CCK Blocks
Try the CCK Blocks module:
http://drupal.org/project/cck_blocks
thanks...
thanks you