Node

Get all nodes attached to a vocabulary,Get all nodes directly attached with a term id,Get all nodes belong to a term id recursively(parent-child taxonomy terms)

<?php

/**
* function to get all term ids inside a vocab in a flat array
* No matter if vocab consists of hierarichal order of terms,you will get all term ids in a flat array.
* @param
* $vocab_machine_name takes vocabulary machine name as parameter.
* @return
* $tids return array of tids in a flat array format
*/
function get_taxonomy_term_ids_inside_vocab($vocab_machine_name) {
$vocab = taxonomy_vocabulary_machine_name_load($vocab_machine_name);
if (is_object($vocab)) {
$term_tree = taxonomy_get_tree($vocab->vid);
if (is_array($term_tree) && !empty($term_tree)) {
foreach ($term_tree as $key => $value) {
$tids[] = $value->tid;
}
} if (empty($term_tree)) {
$tids = array();
}
} else
return "No Vocab Found with the given name";

return ($tids);
}

/**
* function to get all the node ids directly mapped to the given taxonomy terms.
* Returns Flat array of node ids belong to the given term ids.
* @param
* $tid takes term id can be a single term or array of terms.
* @return
* $nid/$nids returns node ids array or sinly node id directly mapped to the given taxonomy term.
*/
function get_nodes_directly_mapped_to_term($tid) {
if (is_array($tid) && !empty($tid)) {
foreach ($tid as $key => $value) {
$nids[] = taxonomy_select_nodes($value);

Read more

Post a message to twitter when a node is published in Drupal 6.x

With the Twitter module, it is easy to post a message to Twitter when a node is created or updated. However, to post the message at any other time requires a bit more work.

Twitter contains a sub module - Twitter Actions. This sub module enables users to post a message to Twitter with any custom business logic. This document will show you how to take advantage of Twitter Actions to post a message to twitter when a node is published. This is a common occurrence in Drupal. Users may want to create a lot of unpublished nodes, and then wait for an admin to approve them, before they are published.

On the Modules page, enable the twitter_actions module.

Step by step guide:

Option A - Use the Rules module:

Set up the following logic.

ON event - Content is going to be saved
IF NOT condition - Unchanged content is published
AND condition - Saved content is published
DO action - Post a message to Twitter

Option B - Build a custom module

1. Go to Site Configuration->Actions, and create a new advanced action called "Post a message to Twitter..."

Read more

Panels 3: How to use variants and views to create node displays. (D7)

You can view your nodes in a custom layout using Panels without having to edit a node template file or use modules such as Content template.

The following example will create a product-page, displaying some of the products content-fields.

Using Panels we will build the node to display in node column.

Requirements for this example

I will asume you have an understanding of the following 3 modules:

Preparation

  • Create a new node type called Product.
    Create Product Type
  • Add the following fields:
  • Product-Image: Use one of the various CCK image field widgets.
    Product Type fIelds
  • Create an Imagecache preset to show the product-thumbnail in a suitable size.
  • Now create some Product content.

Creating a view to display product-fields

  • Create a View that will show node-items.
    Create View
  • Add Field "Product Image".
  • Add Filter-Criteria "Content: Type(=Product)"
Read more

Create a Node in Code

The code below presents a simple example of the means by which you can create a node in PHP code. This example makes no use of the Entity API module.

<?php
function a_page_submit($form, &$form_state) {
  global
$user;

 
$node = new stdClass();
 
$node->title = "YOUR TITLE";
 
$node->type = "YOUR_NODE_TYPE";
 
node_object_prepare($node); // Sets some defaults. Invokes hook_prepare() and hook_node_prepare().
 
$node->language = LANGUAGE_NONE; // Or e.g. 'en' if locale is enabled
 
$node->uid = $user->uid;
 
$node->status = 1; //(1 or 0): published or not
 
$node->promote = 0; //(1 or 0): promoted to front page
 
$node->comment = 1; //2 = comments on, 1 = comments off

  // Term reference (taxonomy) field
 
$node->field_product_tid[$node->language][]['tid'] = $form_state['values']['a taxonomy term id'];

 
// Entity reference field
 
$node->field_customer_nid[$node->language][] = array(
   
'target_id' => $form_state['values']['entity id'],
   
'target_type' => 'node',
  );
 
// 'node' is default,
  // Other possible values are "user" and  "taxonomy_term"

 
$node = node_submit($node); // Prepare node for saving
 
node_save($node);
 
//drupal_set_message( "Node with nid " . $node->nid . " saved!\n");
 
$form_state['redirect']  = 'SOME WHERE';
}
?>
Read more

The Drupal overview

The Drupal way: manageable abstraction

Effective Web design is driven by the need to balance flexibility and simplicity. If a system is too simple, it can only be used for a single purpose - but if it is too flexible, it may be too difficult for new users to learn.

Drupal strives to reconcile these conflicting goals by providing its users with the tools they need to make their own content management solution, while still providing some pre-built components to help them get started. Thus, it can be described both as a content management system (CMS) and a content management framework (CMF) - one system which strives to have the strengths of both, without their deficiencies.

Most CMS's are like a toy boat or truck - specific assumptions have been made about their use, assumptions that would be hard for you to override. Frameworks, on the other hand, provide you with raw materials only - you need to know a programming language and have a clear design vision to put them together.

Drupal is like a Lego kit. Skilled developers have already made the building blocks - in the form of contributed modules - that you need to create a site that suits your needs, whether that is a news site, an online store, a social network, blog, wiki, or something else altogether.

Read more

About nodes

All content on a Drupal website is stored and treated as "nodes". A node is any posting, such as a page, poll, article, forum topic, or blog entry. Comments are not stored as nodes but are always tied to one. Treating all content as nodes allows the flexibility of creating new types of content. It also allows you to painlessly apply new features or changes to all content.

Behind the scenes, the Node module manages these nodes. This module is what lets you:

  • List, sort through, and manage all the content on your site.
  • Set defaults for how all posts are displayed.
  • List and configure the "content types" for your site, and create new ones.

Offering "content types" is a way Drupal allows you to have different kinds of nodes for different purposes. For example, an "article" is one kind of content type, a "book page" another, and a "blog entry" yet another. You can also create new content types of your own.

The Node module manages the creation, editing, deletion, settings, and display of the main site content. Content items managed by the Node module are typically displayed as pages on your site, and include a title, some meta-data (author, creation time, content type, etc.), and optional fields containing text or other data. (Fields are managed by the Field module in Drupal 7.)

Read more
Subscribe with RSS Syndicate content