Drupal

Drupal is an awesome Great Content management system if your webserver has enough resources and you have the technical expertise. It is very customizable and many addons have been written for it. Here you will find tips and thoughts gathered from my experience using drupal.Previous tips were lost in a hard drive crash, bear with us as the content of this site is being rewritten. Tons of new tips coming up... follow @theseobell [sb_child_list]

Interesting Block Snippets

You can for each item click the 'show if following page returns true'. to decide where blocks get displayed

display bock to a particular id

<?php

  global $user;
  if($user->uid == 1 ) {
    return true;
  }
  else
  {
    return false;
  }

display block only to particular node

<?php

$match=FALSE;
$types=array('story' =>1);
if(arg(0)=='node' && is_numeric(arg_(1))) {
  $nid=arg(1);
  $node=node_load(array('nid' => $nid));
  $type=node->type;
  if(isset($types([$type])) {
    $match=true;
  }
}
return $match;
?>

display a block throughout al the forums

<?php
   if(arg(0) == 'forum') {
       return true;
   }
   if(arg(0) == 'node' && ctype_digit(arg(1))) {
      $node =node_loag(arg(1));
      if($node->type == 'blog') {
         return true;
      }
   }
   return false;
?>

 

Basic phptemplate theme creation process

<p>themes are defined by the following steps</p><ul style="margin-left: 40px; "><li>creating a theme directory such as <strong>mytheme/</strong></li><li>adding a theme.info to the theme directory&nbsp;<strong>mytheme/mytheme.info</strong></li><li>adding files you want to override:<ul><li><strong>page.tpl.php</strong> - template for the whole page</li><li><strong>block.tpl.php</strong> - template used to display all blocks</li><li><strong>comment.tpl.php</strong> - template used to display comments</li><li><strong>node.tpl.php</strong> - template used to display each node</li></ul></li><li>in addition, you can add a node number to each of these template name to specify a specific node name.<ul><li><strong>page--1.tpl.php</strong> - will change the page template only for page 1</li><li><strong>comment--1.tpl.php </strong>- will change the template for the first comment</li></ul></li></ul>

Interesting snippets

You can for each item click the 'show if following page returns true'. to decide where blocks get displayed

display bock to a particular id

<?php

  global $user;
  if($user->uid == 1 ) {
    return true;
  }
  else
  {
    return false;
  }

display block only to particular node

<?php

$match=FALSE;
$types=array('story' =>1);
if(arg(0)=='node' && is_numeric(arg_(1))) {
  $nid=arg(1);
  $node=node_load(array('nid' => $nid));
  $type=node->type;
  if(isset($types([$type])) {
    $match=true;
  }
}
return $match;
?>

display a block throughout al the forums

<?php
   if(arg(0) == 'forum') {
       return true;
   }
   if(arg(0) == 'node' && ctype_digit(arg(1))) {
      $node =node_loag(arg(1));
      if($node->type == 'blog') {
         return true;
      }
   }
   return false;
?>

 

Interesting links

 

Refreshing a div from with fade in:

Code: [Select]<script type="text/javascript">
$(document).ready(function() {
$("#responsecontainer").fadeOut("fast").load("getrows.php").fadeIn("slow");
var refreshId = setInterval(function() {
$("#responsecontainer").fadeOut("fast").load('getrows.php').fadeIn("slow");
}, 5000);
$.ajaxSetup({ cache: false });

[Code]...

Posting to a form from php

 

Drush

About Drush

Drush is an awesome command line interface for Drupal

If you have multiple sites (and even in cases of single site use) and you are not using Drush, you are missing out

Installing Drush:

 
pear channel-discover pear.drush.org
pear install drush/drush
 
now, you can check drush is installed by typing "drush from command line"
_ mkdir /etc/drush
_ cp /usr/share/pear/drush/examples/example.drush.ini /etc/drush/drush.ini
 
when done, uncomment the disable_function="" line
 

Useful commands

et voilà, you are ready to boost your productivity using drupal by an order of magnitude. Here are some of the commands I use

default theme.info

each theme has a theme.info file specify theme files and settings

; $Id: mytheme.info, v 1 date
; comments start if a semi column, previous comment was source contro comment

name = My theme name
description = what gets shown to users selecting themes. like 'custom them for example.com'
version = 7.x

default page.tpl.php

here is a sample page.tpl.php. note if the template does not exist, a default template is used. Comments are also optional but included here for code clarity

<head>
  <title>
  <?php   print $head_title; //print the page title  ?>
  </title>
  <?php print head; //print header ?>
  <?php print $styles; //print relevant styles ?>
  <?php print $scripts; //print page scripts ?>
</head>

 <?php if($site_slogan); ?>
    <div id='site-slogan'><?php print $site_slogan; ?></div>
 </div>

<?php endif; ?>

 

 

Drupal tips

Here are a few things that I have learned over time

Drupal Install Checklist

This is not meant to be a full fledged install tutorial... There exists plenty of good install tutorials are available... This is more a checklist of the 10 things I do when drupal is installed (I wish drupal would do that by default). Note that drush commands are included... so technically, it is possible to daisy chain most of these commands in a bash script file... making enabling modules on a new install a breeze.

 

Obviously, many more steps are needed from there but this is a good way to get a decent head start.