Aug 05

How to create new block region in Drupal 7

Then following are the steps demonstrate how to create a new block region in Drupal 7.

Step 1:
Open up your theme’s .info file and add the following line:
regions[new_region] = New Region

Step 2:
Now go to the your site url/admin/structure/block and select which block you want to show in your newly create region, and save the your choice.

Step 3:
Then you’ll need to print out your new region in your page.tpl.php file which goes something like this now:

<?php if ($page['new_region']): ?>
<div id=”new_region”><div>
<?php print render($page['new_region']); ?>
</div></div>
<?php endif; ?>

Aug 05

Drupal node indexing

How to index a node at time of its creation/modification in Drupal7?

Drupal would not indexing nodes at the time of its creation/modification.
At the time of executing the cron script drupal indexing all the nodes those are yet not indexed.
That is why if we want to search a node in site(at user end) just after its creation/updation we can’t get this node as the node is not indexed.So our objective is indexing node at the time of its creation/updation(means just after saving it into the database).Drupal provides us a hook(hook_node_insert and hook_node_update) which is execute just after node saved into the database and also provide a function(_node_index_node) which can index a node.
So, we just need to add the following functions in any custom module.
/* Implementing hook_node_insert */
function {module_name}_node_insert($node) {
 //calling the the below function to index the current node.
 _node_index_node($node);
}
/* Implement hook_node_update */
function {module_name}_node_update($node) {
 //calling the the below function to index the current node.
 _node_index_node($node);
}
*NOTE: replace {module_name} by your module name.
After adding the above functions if we create/updation any node it will immediately indexed and you are able to get the created node in your search result at user end.