Tag Archives: Drupal 7

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

Drupal 7 – Enable forum topic view count in Advanced Forum

We know that we could enhance the core Forum module in Drupal 7 with the help of the Advanced Forum module.
Drupal 7 – Strengthen the core Forum module by Advanced Forum

Today, i would like to share how to add the forum topic view count on the forum topic listing page.
Continue reading Drupal 7 – Enable forum topic view count in Advanced Forum

Drupal 7 – Strengthen the core Forum module by Advanced Forum

I am now working a new website project which includes a forum. With the Forum module bundled in the Drupal core. It is easy to build a forum based Drupal site. In the coming days, i would like to share suggestions when working on forum site.

First of all, you could equip your Drupal website with the basic forum features by enabling the core Forum module. However, that may be not enough for meeting the client’s requirements or it is difficult to customize it. That’s why we need the Advanced Forum module.
Continue reading Drupal 7 – Strengthen the core Forum module by Advanced Forum

Drupal 7 – Default comment subject with Token

Previously we talked about reply Drupal node or comment with quote.
Drupal 7 – Quote post or comment on reply

By default, Drupal will make use of the beginning text of the comment body as the comment subject if it is not filled. This leads to a confusing subject title when using the Quote module. A workaround is to automate the comment subject title using the Re: Comment subjects module.
Continue reading Drupal 7 – Default comment subject with Token