Node content
This snippet will show the content of a node with a very simple print_r($node) This might be useful if you're revising or creating a module.
This snippet has been tested on Drupal 5.5
I suggest you to place this block at the bottom of a page or in the footer which leaves more space. If your style doesn't show a tree-like structure, you might want to add the CSS after the snippet.
snippet
<?php
if (arg(0) == 'node' && is_numeric(arg(1)) && is_null(arg(2))) {
$nid = (int)arg(1);
$node = node_load($nid);
print "<pre>";
print_r($node);
print "</pre>";
}
?>style suggestion
pre {
text-align: left;
}
Another Idea
I had to write a block snippet this week that simply shows the body content for the most recent blog entry for a specific user. I know I could have used a view to do this, but I'm trying to get into module development, so I wanted to do it the long way. Is this an acceptable way to do this? I actually used a modified version of this to display the body of a single node inside a block. I'm relatively new to drupal, so any suggestions are appreciated!
<?php
//the purpose of this PHP block snippet is to create a block that displays the body content for the latest blog entry for any given user
// use db_query to select the latest 'blog' node created by userID #6
$result = db_query("SELECT n.nid, n.title FROM {node} n WHERE n.type = '%s' AND n.uid = '%d' LIMIT 1", "blog", 6);
//loop through the results of the above query
while ($row = db_fetch_object($result)) {
//use node_load to get all the information for the node
$displayContent = node_load($row->nid);
//display the first 200 characters of the body
echo substr($displayContent->body,0,200);
}
?>
...
<br/><br/>
<a href="node/<?php echo $displayContent->nid?>">read more</a>
<br/>
<a href="user6blog">see all</a>
acceptable
Of course it's acceptable to do a module ! Although you have to consider the long-term usage of it : you will need to keep it updated ; the advantage of using the view is that all the inner workings will be kept updated as so many people use it, even if the developers drop it, it will be picked up by others.
I'm sorry my friend this isn't a support thread, you'd have better luck with them as I'm quite busy.
Display teaser from a single node inside a block
Often times, I get the request to have an area of a page simply 'editable', meaning that it doesn't need to be a view, or use a module or anything special. Just a simple box that the client can update on their own. I know you can write custom blocks that do just that, but I don't want to give this client admin rights to manage blocks, because they will click around and break their site in a matter of minutes. I came up with this stupidly simple snippet to load a specific node's teaser into a block. Is this a reasonable and secure way to do this? As always, I'm welcome to comments and suggestions.
<?php
$node = node_load(75);
print($node->teaser);
?>
<a href="welcome">read more</a>
<?php
//create a link that will allow them to edit this node
if (user_access('administer nodes')): ?>
<a class="editLink" href="<?php print 'node/'.$node->nid ?>/edit" title="
<?php print t('Edit') ?>">[edit]</a>
<?php endif; ?>