Naoise Golden
Naoise Golden

Reputation: 8913

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 information 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

Upvotes: 2

Views: 2173

Answers (3)

kopelitsa
kopelitsa

Reputation: 4261

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!

Upvotes: 0

starsinmypockets
starsinmypockets

Reputation: 2294

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

Upvotes: 2

Shoaib Nawaz
Shoaib Nawaz

Reputation: 2320

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";
    }
?>

Upvotes: 1

Related Questions