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:

PHP – Get the next month by strtotime

I am working on a Hotel Booking website. The booking feature is provided by Hotel Booking System for Ubercart. But this module is not actively maintained so there are some bugs which i have to fix it for myself.

One of the bug is about strtotime(‘+1 month’). Intuitively, you may think you could get a date of next month. But here comes the problem. Assume you are now on 31st Jan. Since February only has 28 days (sometimes 29), strtotime(‘+1 month’) will return 3rd Mar.
Continue reading PHP – Get the next month by strtotime

Eureka! – 2012 Review

Happy new year!

2012 is a special year for me because not only i have turned myself from an employee to an freelancer, and also i have implemented my own idea as a real website called QPon. Although this idea is not working at all in HK, it is really an unforgettable experience to me.

On the other hand, i completed the another unforgettable life experience which is the round trip Taiwan cycling in October.

Looking forward to 2013 and wish you all have a fruitful year!

  • 2012 Jan – 49,045
  • 2012 Feb – 75,742
  • 2012 Mar – 78,831
  • 2012 Apr – 54,569
  • 2012 May – 53,906
  • 2012 Jun – 48,489
  • 2012 Jul – 50,296
  • 2012 Aug – 63,454
  • 2012 Sep – 59,668
  • 2012 Oct – 65,400
  • 2012 Nov – 70,705
  • 2012 Dec – 66,740
  • 2012 Total – 736,845

賣夢的老人 – 鹽埕區的莊朱玉女嬤嬤

更新於2015-03-01: 莊嬤嬤,一路好走… – 「賣夢老人」十元自助餐嬤走了 家屬成立慈善會傳愛心

一年就快又過了,2012年的除夕,給大家一個中國人的故事,在此祝福莊嬤嬤。

 

之前釣魚臺鬧得熱哄哄,好像不出來爭釣魚台就不是中國人,其實有無想過中國人的定義是什麼?

是否出生在一個叫中國的地方就是中國人?

是否黃皮膚,講普通話就是中國人?

是否拿著一個”中華XX共和國”護照,就可以叫自己做中國人?

我認為一個比較嚴謹的定義,應該是一個人了解這個叫”中國”的地方的文化和歷史,並可以活出並守護這中國傳統文化的人,才有資格稱為中國人。

以下的婆婆,她就是我心中所想的中國人。

在質疑別人的行為或思想不是中國人應有之前,先想想中國人的的定義是什麼,看看自己的思想與行為,看看你現在生活的環境,還有幾多是屬於這個地方的傳統與文化。


 

 

【一個銅板,許你一個夢!】
Continue reading 賣夢的老人 – 鹽埕區的莊朱玉女嬤嬤

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:

Dream BIG and go for it =)