Tag Archives: Drupal Development

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

QPon – Made by Coupon

Made by Coupon
QPon is an online coupon platform for both shop owners and customers. The motivation of this project is to provide a free platform for the shop owners to promote their brand and products by offering discounts to customers. On the other hand, customers could find what they need in QPon.

One of the main feature which differentiate QPon from other typical coupon websites is the presentation. On the homepage, you could find many coupons flowing in a pool. Here, we name the coupon as QPon. The size of the QPon depends on the redemption ratio. The more people redeem it, the bigger it is until it meets the redemption quota and every QPon has equal probability could be viewed by the potential customers.

Continue reading QPon – Made by Coupon

Drupal 7 – Customize the exposed filter selection list

Yesterday we have talked about how to use selection list for selecting Entity reference in Views exposed filter.
Drupal 7 – Selection list for Entity reference in Views exposed filter

Now i want to have more control on the selection list. For example, i have a content type called competition and i want to limit the number of options in the Entity reference selection list. In this case, we have to create a custom module and alter the views_exposed_form.
Continue reading Drupal 7 – Customize the exposed filter selection list

Drupal – Disable the default node page

In Drupal 6, the default <front> page has the path /node which will list out the latest nodes. Although we could point the <front> page to another path, the /node page is still accessible.

Create a custom module and add the following piece of code would help redirecting /node page back to the <front> page.

/**
 * Implementation of hook_menu_alter().
 */
function YOUR_MODULE_NAME_menu_alter(&amp;$items) {
  $items['node']['page callback'] = '_internal_custom_function_name_here_redirect_to_frontpage';
}

/**
 * Redirect back to the frontpage for specific pages.
 */
function _internal_custom_function_name_here_redirect_to_frontpage() {
  if($_GET['q'] == 'node') {
    $_REQUEST['destination'] = &quot;&lt;front&gt;&quot;;
    drupal_goto();
  }
}

 

I haven’t tried it in Drupal 7, please let me know if you have any idea.

Done =)

Reference: disable the default node page