Display node information in block
How can I create a custom block snippet (or download an available module) that would display a selected amount of informa开发者_如何学JAVAtion about a node in Drupal (6)? (i.e. author, creation date and published status)
I would later make this node available to admin
user and only in certain content types
, as a mean of seeing node information in-situ while browsing the web only as admin (this part I know how to achieve).
Thank you
I would use the Views
& Context
modules.
You can use a block display in Views
to output the desired fields. Add an argument, then select the option to get the argument from the url.
Context
module allows you to (among other things) set access rules based on roles.
I use both of these modules in all of my Drupal installs and find them quite helpful.
http://drupal.org/project/views
http://drupal.org/project/context
You can create a custom block (admin/build/block/add
)
Make sure PHP Filter
module is enabled already
For your block body select input filter as PHP Code
Add these lines in the body to load node information
<?php
if(arg(0) == 'node' && is_numeric(arg(1))){
$node = node_load(arg(1));
$user = user_load(array('uid' => $node->uid));
print "Author: " . l($user->name, 'user/' . $node->uid);
print "Creation date: " . date('m/d/y h:i:s', $node->created);
print "Publish Status: " . ($node->status) ? "Published" : "Unpublished";
}
?>
Views are totally advisable, writing custom code for something like that is a bad practice... In general the combination CCK & views is very poweerful in Drupal!
精彩评论