The following piece of code will update a field of a specific content type by SQL and it is written in a custom module with hook_cron(). Since it updates the database table directly so you have to use it with extreme caution.
Continue reading Drupal 7 – Batch update nodes by cron
Category Archives: CMS
Drupal 7 – Add Javascript files on specific paths by template.php
In my previous post, Drupal 7 – Add Javascript files on specific paths by custom module, we try to add .js files for specific paths by creating a custom module. Actually we could implement the same feature by using the theme template.php. Here is an example.
Continue reading Drupal 7 – Add Javascript files on specific paths by template.php
Drupal 7 – Override the term path inside Tagadelic Tag Cloud
Implement tag cloud is easy in Drupal. You can find the module called Tagadelic in the my previous post.
Drupal 7 – Create a Tag Cloud with Tagadelic
But the term path inside the tag cloud is always fixed as default which is taxonomy/term/[tid]. I tried to override it by the Entity Path module but no luck. Luckily i find a workaround to override it. Actually Tagadelic is not just a simple Drupal module but also a API system. The following theme function theme_tagadelic_weighted() determines the term path in Tagadelic.
Continue reading Drupal 7 – Override the term path inside Tagadelic Tag Cloud
Drupal 7 – Create a Tag Cloud with Tagadelic
If you want to create a Taxonomy Tag Cloud in Drupal, Tagadelic is a very good module which could serve your purpose.
After you have enabled the module, you could find some new blocks which are named as Tags in [VOCABULARY NAME]. Enable the block and your tag cloud is ready.
Continue reading Drupal 7 – Create a Tag Cloud with Tagadelic
Drupal 7 – Get specific nodes using EntityFieldQuery
Starting from Drupal 7, you can now select nodes with conditions using the EntityFieldQuery class. The following are a few examples.
Continue reading Drupal 7 – Get specific nodes using EntityFieldQuery
Drupal 7 – Limit the number of countries in the country list of the Location module
If you want to include location information in your content type. The Location module could help. But by default, the list of selectable countries are very long and sometimes we may want to limit it to a few countries only. This can be done by creating a custom module but it only works for Location CCK but not for Node Location and User Location
1. Download and enable the Location and Location CCK modules
Continue reading Drupal 7 – Limit the number of countries in the country list of the Location module
Drupal – Add additional validation on Drupal form
We can use a custom module to add additional validation on any Drupal form without affecting the build-in validation. Add the following 2 functions in your .module file.
Continue reading Drupal – Add additional validation on Drupal form
Drupal – Create PDF file with dompdf
dompdf is a HTML to PDF converter in PHP. In the GShop project, I need it for sending email with PDF attachment by the Ubercart Conditional actions in Drupal. The following example is done in Drupal 6 with Ubercart.
1. Download and extract the dompdf library to <drupal>/sites/all/libraries.
Continue reading Drupal – Create PDF file with dompdf
Drupal – Get the absolute file path of your Drupal installation
You can get the absolute file path of your Drupal installation as follow.
echo realpath(".");
// output: /var/www/drupal-6.22
For more examples, please refer to Computer tips by Siripong – get absolute path in drupal modules
Done =)
Drupal 7 – Add Javascript files on specific paths by custom module
In the past, i always added js files on theme level. This is not a good approach because the aggregated theme js will be quite large and it is loaded on every pages even js code is not used.
So this time i try to add the js on specific path only when it is needed. This is done by creating a custom module. Let’s name the custom module eureka_js.
1. Inside the eureka_js module folder, we have the following files.
- js/eureka.js
- eureka_js.info
- eureka_js.module
Continue reading Drupal 7 – Add Javascript files on specific paths by custom module