Category Archives: CMS

Drupal 7 – Create a taxonomy term selection list of a specific vocabulary @ 1

Next: Drupal 7 – Create a taxonomy term selection list of a specific vocabulary @ 2

I want to create a HTML selection list which contains the taxonomy terms of a vocabulary. When a option is selected, the browser will go to the selected term page. In this post, i would like to share how to generate a selection list by PHP.

I have a vocabulary which has terms in 2-level. The selection list could generated as follow.
Continue reading Drupal 7 – Create a taxonomy term selection list of a specific vocabulary @ 1

Drupal 7 – Disable the node view URL for some content types

Sometimes the content types we created are only used in Views. We don’t want to have the node view page for those content. The following solution would turn those unwanted node view pages to 404 not found.

Create a custom module and implement the hook_node_view() as follow.
Continue reading Drupal 7 – Disable the node view URL for some content types

Drupal 7 – Override the .tpl.php in Advacned Forum

Advanced Forum has some default themes which are located @ sites/all/modules/advanced_forum/styles/<theme>.

Naked/Naked Stacked themes could be used for customization. So copy the .tpl.php which you want to customize in the sites/all/modules/advanced_forum/styles/naked folder to your theme folder.

For example, i want to customize the advanced-forum.naked.author-pane.tpl.php.
Continue reading Drupal 7 – Override the .tpl.php in Advacned Forum

Drupal 7 – Customized comment.tpl.php for specific content type

The comment.tpl.php is located @<drupal-root>/modules/comment/comment.tpl.php. If you want to customize it for different content type. Copy it to your theme folder and rename it to

  • comment–node-<content-type>.tpl.php

For example, the machine name of Article is article. So the file name should be comment–node-article.tpl.php.

Done =)

Reference:

Drupal 7 – Add extra text on the LightBox2 popup

Update @ 2014-01-24: Instead of hacking into LightBox2 module, you can use the hook_js_alter() as suggested by Sunny Gambino. Thanks Sunng. =D

 

LightBox2 will show the image title as caption in the popup.
drupal7-add-text-to-lightbox2-1
 

But apart from the title, i would like to add extra text to the popup. Unfortunately there is no proper way to do it. So i have to hack into the lightbox.js.
Continue reading Drupal 7 – Add extra text on the LightBox2 popup

Drupal 7 – Get the number of comments by user

Yesterday we talked about counting the number of nodes by user.
Drupal 7 – Get the number of nodes by user

We could also use similar approach for counting the number of comments by user.

1. Add the following function in your theme template.php

function <theme>_get_user_comments_count($uid) {
  $query = db_select('comment', 'c');
  $query->condition('uid', $uid, '=');
  $query->condition('status', '1', '=');
  $query->addExpression('COUNT(1)', 'count');
  $result = $query->execute();

  if ($record = $result->fetchAssoc())
    return $record['count'];
  
  return 0;
}

Continue reading Drupal 7 – Get the number of comments by user

Drupal 7 – Get the number of nodes by user

1. Add the following function in your theme template.php

function <theme>_get_user_nodes_count($uid) {
  $query = db_select('node', 'n');
  $query->condition('uid', $uid, '=');
  $query->condition('status', '1', '=');
  $query->addExpression('COUNT(1)', 'count');
  $result = $query->execute();

  if ($record = $result->fetchAssoc())
    return $record['count'];
  
  return 0;
}

Continue reading Drupal 7 – Get the number of nodes by user

Drupal 7 – Get number of returned rows on db_query()

db_query() returns a DatabaseStatementInterface object which has a function for retrieving the number of returned rows in the last SQL statement.

You could use the following piece of code to get the total number of nodes in Drupal.

$num_of_nodes = db_query('SELECT nid FROM {node}')->rowCount(); 

 

Done =)

Reference:

Drupal 7 – Customize the Author Pane in Advanced Forum

Here is another topic about working on Drupal forum based website. So if u have Advanced Forum installed. Your forum topic should looks like the following picture.
drupal7-advanced-forum-author-pane-1
 

It should be better to add more author information instead of just the username and the user picture. This could be done by the Author Pane module.
Continue reading Drupal 7 – Customize the Author Pane in Advanced Forum