Thursday, November 17, 2011

Creating a Page with links belonging to certain taxonomy terms

<? php// paste this code into a custom block of type=php
// customize the $tax array and the $subject as needed
$tax = array(3, 6);$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);?>

A page that returns the first 5 terms for a taxonomy 
<? php
$taxo_id
= 3;$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;?>

No comments:

Post a Comment