I found a code that displays all titles from a taxonomy. I want to publish only the first 4 titles. What code I need to put there?

// paste this code into a custom block of type=php
// customize the $tax array and the $subject as needed
$tax = array(2);
$operator = "or";
$result = taxonomy_select_nodes($tax, $operator);
while ($obj = db_fetch_object($result)) {
  $node = node_load(array('nid' => $obj->nid));
  $items[] = l($node->title, "node/". $node->nid);
}
return theme('item_list', $items);

Comments

enginera’s picture

This code displayes 5 titles. But I want only the Newest 5.
Any help? How to sort database query?

$taxo_id = 17;
$sql = "SELECT node.title, node.nid FROM node INNER JOIN term_node ON node.nid = term_node.nid WHERE term_node.tid = $taxo_id LIMIT 5";
$output .= "<ul>";
$result = db_query($sql);
while ($anode = db_fetch_object($result)) {
$output .= "<li>".l($anode->title, "node/$anode->nid")."</li>";
}
$output .= "</ul>";
return $output;
hruodland’s picture

Does anyone know what the answer is?

UPDATE: it should work in the example to make the line ending "LIMIT 5";" end "ORDER BY node.nid DESC LIMIT 5";" instead.

Dublin Drupaller’s picture

Have you tried the taxonomy_browser module? It might have the SQL statement or functionality you're looking for...

http://drupal.org/project/taxonomy_browser

Would be great if you could post the solution here if you manage to do it in a php page: PHP page snippets: putting dynamic content into your main page

Dub

DUBLIN DRUPALLER
___________________________________________________
A drupal user by chance and a dubliner by sheer luck.
Using Drupal to help build Artist & Band web communities.

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

bassem’s picture

sorry for this simple question, but how would you remove the listing's limit, to set it to no limit..

cheers,
b.