l('<link text>', '<link path>', array('attributes' => array('class' => array('class-a', 'class-b'))));
Done =)
Reference: Drupal API – l()
l('<link text>', '<link path>', array('attributes' => array('class' => array('class-a', 'class-b'))));
Done =)
Reference: Drupal API – l()
The following piece of code will print the Nice Menus block.
$menu = theme('nice_menus', array('id' => 1, 'direction' => 'down', 'depth' => 1, 'menu_name' => '<menu-machine-code>', 'menu' => NULL));
print $menu['content'];
you can input any value in the <id> parameter and the rendered menu will have the HTML tag id = nice-menu-<id>. Just make sure there is no duplicated nice menu id in the same page.
Done =)
Reference: How to display nice_menus programmatically in Drupal 7
If you want to update the node programmatically, the following example update the node title and the value of the custom field called field_example.
// Load the node with nid = 1
$nid = 1;
$a_node = node_load($nid);
$a_node->title = 'new title';
$a_node->field_example['und'][0]['value'] = 'new value';
// Save the node
node_save($a_node);
// If you want to populate the node author and creation date, call node_submit() before saving
/*
if($a_node = node_submit($a_node)) {
// Save the node
node_save($a_node);
}
*/
Done =)
Reference: fooninja.net – Updating nodes programmatically in Drupal 7
We can get the number of returned rows in db_select() by ->rowCount().
// Get the number of nodes created by administrator
$query = db_select('node', 'n');
$result = $query->fields('n', array('nid'))->condition('uid', 1, '=')->execute();
return $result->rowCount();
Done =)
Reference: Drupal forum – get count with db_select
The following example is base on the database table i created previously.
Drupal 7 – Insert database record on module installation
We can add the orderRandom() to sort the records randomly. Here is an example.
Continue reading Drupal 7 – Sort by random when using db_select()
We could write custom module and use the hook_schema() to create new database table. The following <module>.install file will create a table called eureka_variables.
Continue reading Drupal 7 – Insert database record on module installation
We can select nodes by conditions using EntityFieldQuery.
Drupal 7 – Get specific nodes using EntityFieldQuery
After I have installed the Date module, I could create a content type with a date field called field_expiry_date. When i setup this field, there are 3 date options in the field type.
Continue reading Drupal 7 – Set a date fieldCondition in EntityFieldQuery
Yesterday we talked about defining a datetime field for the table created by custom module.
Drupal 7 – Create a Datetime field in hook_schema() @ 1
As i have mentioned in the above post, the datetime field is no longer support by the Drupal Schema API. If you don’t want to use the datetime field, you can try to save the datetime in timestamp format and stored it in an int column.
Continue reading Drupal 7 – Create a Datetime field in hook_schema() @ 2
Next: Drupal 7 – Create a Datetime field in hook_schema() @ 1
If your custom module requires an additional table in the Drupal database, you have to create the .install file and define the schema inside it. In Drupal 7, the datetime field is no longer support by the Drupal Schema API. If you want to create a datetime field, you have to use the mysql_type or pgsql_type. Here is an example.
Continue reading Drupal 7 – Create a Datetime field in hook_schema() @ 1
I want to create a URL which will redirect to the latest node of a specific content type so i write a custom module. In this example, the content type car is used.
latest_car.info
name = Latest car description = Create a URL which will redirect to the latest car node. package = Eureka; version = 7.x-1.0 core = 7.x
Continue reading Drupal 7 – Create a URL which display the latest node of a specific content type