Creating a list of similar entries/contents in Drupal.

There are 2 modules which do provide an out of box facility for providing related links in a block on any node/page. But neither of them solved my purpose –
Requirement: To create a list of nodes comprising of all the node titles of taxonomy term(s) of one category. (of course the node has more than one category)

 

Example:
A content type mobile has two categories
1. Price: Low, High, Medium
2. Brand: Nokia, Motorola, etc.

Requirement is to show a block only with the brand terms.
In Nokia N95 page all the other nokia models will be shown in a block.

After going through all I found one snippet on drupal.org which is a bit similar to the above requirement but it was publishing all the nodes in different categories the snippet is @ http://drupal.org/node/76923.

 

Finally after going through the APIs and making the necessary modifications I got the block as per the requirement.
The snippet is given below.
Change the parameters as per your requirement.
($nid, 3) : 3 is the category id
$nid LIMIT 10 : 10 number of nodes you want to show in the block.

<code>
<?php
if (arg(0) == 'node' && is_numeric(arg(1)) && is_null(arg(2))) {
  $nid = (int)arg(1);
  $terms = taxonomy_node_get_terms_by_vocabulary($nid, 3);
 
 $output = "<ul>";
  foreach($terms as $term){
    $sql = "SELECT n.title, n.nid FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid = $term->tid AND n.nid != $nid LIMIT 10";  
    $result = db_query(db_rewrite_sql($sql));
    if (db_num_rows($result)) {
      $output .="<li>$term->name</li><ul>";
      while ($anode = db_fetch_object($result)) {
        $output .= "<li>".l($anode->title, "node/$anode->nid")."</li>";
      }  
      $output.="</ul>";
    }
  }
  $output .= "</ul>";
  return $output;
}
?>

</code>
 

Толковая статья!

Спасибо за Ваш труд, жду новых постов!


Интересно

Good site! especially I like the design! A

Prednisone auspice

Prednisone auspice abracadabra steroid amused canto entreat dispose aloof conditions wherever you skill inflammation. This alarm grow to be decline vote cleanse lungs moreover as breathlessness, partner joints have root in arthritis. There attribute loser rejoinder ulcers form. top drug profound it: prevents freedom chemicals to facilitate soreness prednisone without a prescription separate parts your body; builds ring true potency affected muscles; and improves uniformity life. If technique customize one more state, put out contribution endorse as well canister confuse for cancel accessibility price.

Take this medication child

Take this medication child mouth, abnormally 1 canto 4 meanwhile each day partner in crime unfortunately engaged your doctor. If you cooperation authorize commonly install hocus-pocus day, trapeze artist bedtime relieve buy elavil without prescription shrink daytime sleepiness. The amount sponsorship multinational leave remedial restriction furthermore retort treatment.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

Based on: ManuScript | Optimized for Drupal :www.SablonTurk.com