Drupal: .htaccess Access Deny
August 21, 2014 – 7:59 am | No Comment

In this article I will tell how to forbid access to certain resources for some clients. The instructions will include descriptions of different directives.

Read the full story »
CSS Templates

Contain reviews and news about CSS Templates.

Freebies

Contain freebies such as icons, graphics, headers and images for your websites.

Fun Stuff

Contains other fun stuff for entertainment or interesting site showcase.

How-To

Contain technical elaborations on some specific workarounds or common tweak.

Joomla Templates

Contains reviews and news about Joomla templates.

Home » How-To

Drupal: How to Get Know Type of Current Node

Submitted by on April 7, 2010 – 3:16 pm2 Comments

Problem:

It is necessary to get know type of the displayed node. There is no such info in Edit form.

Solution:

Alternatives
  • Block with РНР code that shows node type
  • Nodetype module

Block with PHP code that shows node type

Create a block with PHP input format and insert the following code to the block body:

<?php
if (arg(0)==’node’ && is_numeric(arg(1))) {
$node =  node_load(arg(1));
echo ‘Тип текущей ноды: ‘. $node->type;
}
?>

Bock visibility: “Show block on specific pages: Show on every page except the listed pages." The block will be shown on nodes’ pages only – this is defined in the code.

It is better to show the lock for site admin only – just specify the desired role.

Nodetype module

You can install Nodetype module which allows to change node type.

ON the edit page for a node, you will find the drop-down list (select list). The current node type will be the default there. Select the node type and save settings.

2 Comments »

  • Kadimi says:

    This code is faster

    In my tests:
    – node_load(): 16ms
    – db_query(): 0.4ms

    arg(1)));
    foreach($result as $record)
    $type = $record->type;
    echo ‘Node type is: ‘. $type;
    }
    ?>

  • Kadimi says:

    This code is faster

    In my tests:
    – node_load(): 16ms
    – db_query(): 0.4ms

    if (arg(0)==’node’ && is_numeric(arg(1))) {
    $result = db_query(‘SELECT n.type FROM {node} n WHERE n.nid = :nid’, array(‘:nid’ => arg(1)));
    foreach($result as $record)
    $type = $record->type;
    echo ‘Node type is: ‘. $type;
    }

Leave a comment!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.