Return to Snippet

Revision: 7927
at August 21, 2008 10:19 by aleprieto


Initial Code
<?php
/**
* This code snippet is used to show selected node content
* in the block based on the current node id.  The idea is
* to show relevant sidebar content that matches up with the
* main content.  One block instead of several.
*
* If logged in user has admin nodes then show an Edit link.
*/
if ( arg(0) == "content" || arg(0) == "node" )
{
  //Choose which node to put into the block
  switch (arg(1))
  {
    case "10":  //nid of the home page
      $xNode = 58; //nid of content to load
      break;
    case "about":  //this page is a view made with Views module so no nid
      $xNode = 59;
      break;
    case "40":
      $xNode = 69;
      break;
    default:
      return FALSE;
  }

  $node = node_load($xNode);
   
  //Add an edit link for admins
  if (user_access('administer nodes'))
  {
    $nodeurl = url('node/'. $node->nid);
    print('<a href="'.$nodeurl.'">[edit]</a>');
  }
   
  $nodeout = node_view($node);
  print $nodeout;
 
}

/*  // Helpful debugging info.
$x=arg(0);
$y=arg(1);
$z=arg(1);
print "<p>x=$x<br />y=$y<br />z=$z</p>";
// ==End Debug==  */
?>
‹ Simple book-like navigation using menu itemsupAggregator headline display with date ›

Initial URL
http://drupal.org/node/273665

Initial Description
Fairly simple way to match sidebar content with the main content for several pages without the need to create multiple blocks or the hassle of putting content in a block.

For example, your Home, About and Contact pages all have a sidebar with some accompanying content which is different for each.

   1. Create pages (nodes) for each of the sidebar content and note the node ID.
   2. Add a block and paste in this code snippet
   3. Edit the Switch/Case part of this snippet for your nodes
   4. Enable the block for content/* and node/*

Initial Title
Drupal: Add node content into block depending on page ID

Initial Tags
module, drupal

Initial Language
PHP