Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By lophas on
Provides book-style navigation
- for any node types browsed in taxonomy tree
- images
- events
<?
// $Id: uninav.module,v 1.0 2005/07/01 16:18:16 lophas
/*
Provides book-style navigation
- for any node types browsed in taxonomy tree
- images
- events
Installation:
1. copy uninav.module yo your modules directory
2. Enable uninav module in admin/modules
3. edit your node.tpl.php and change "$node_url" to "$node->node_url"
under <!-- BEGIN: title -->
Thats's all!
*/
function uninav_nodeapi(&$node, $op, $arg) {
switch ($op) {
case 'load':
if($node->nid && function_exists("book_load")) return array("book" => book_load($node));
break;
case 'view':
if($node->nid) {
if($node->tid) $tid=$node->tid;
elseif(arg(0)=='taxonomy' && arg(1)=='term' && is_numeric(arg(2))) $tid=arg(2);
if($tid && !$node->book && $node->type!='image') $node->node_url.="?tid=$tid";
$node = theme('uninav_node_navigation', $node);
}
break;
}
return $ret;
}
function theme_uninav_node_navigation($node) {
$tid=$_GET[tid];
if($tid && !$node->book) {
$output .= '<div class="book">';
if ($prev = db_fetch_object(db_query_range(db_rewrite_sql('SELECT n.nid, n.title FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid = %d AND (n.sticky < %d OR (n.sticky = %d AND (n.created < %d OR (n.created = %d AND n.nid < %d)))) AND n.nid != %d AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC, n.nid DESC'), $tid, $node->sticky, $node->sticky, $node->created, $node->created, $node->nid, $node->nid, 0, 1))) {
$links .= '<div class="prev">';
$links .= l(t('previous'), drupal_get_path_alias("node/".$prev->nid), array('title' => t('View the previous page.')),"tid=$tid");
$links .= '</div>';
$titles .= '<div class="prev">'. check_plain($prev->title) .'</div>';
}
else {
$links .= '<div class="prev"> </div>'; // Make an empty div to fill the space.
}
if ($next = db_fetch_object(db_query_range(db_rewrite_sql('SELECT n.nid, n.title FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid = %d AND (n.sticky > %d OR (n.sticky = %d AND (n.created > %d OR (n.created = %d AND n.nid > %d)))) AND n.nid != %d AND n.status = 1 ORDER BY n.sticky ASC, n.created ASC, n.nid ASC'), $tid, $node->sticky, $node->sticky, $node->created, $node->created, $node->nid, $node->nid, 0, 1))) {
$links .= '<div class="next">';
$links .= l(t('next'), drupal_get_path_alias("node/".$next->nid), array('title' => t('View the next page.')),"tid=$tid");
$links .= '</div>';
$titles .= '<div class="next">'. check_plain($next->title) .'</div>';
}
else {
$links .= '<div class="next"> </div>'; // Make an empty div to fill the space.
}
$links .= '<div class="up">';
$links .= l(t('up'), drupal_get_path_alias('taxonomy/term/'. $tid), array('title' => t('View this page\'s parent section.')));
$links .= '</div>';
$output .= '<div class="nav">';
$output .= ' <div class="links">'. $links .'</div>';
$output .= ' <div class="titles">'. $titles .'</div>';
$output .= '</div>';
$output .= '</div>';
$node->body = $node->body.$output;
} else if($node->type=='blog' && !$node->book) {
$output .= '<div class="book">';
if ($prev = db_fetch_object(db_query_range(db_rewrite_sql('SELECT n.nid, n.title FROM {node} n WHERE n.type = "blog" AND n.uid = %d AND (n.sticky < %d OR (n.sticky = %d AND (n.created < %d OR (n.created = %d AND n.nid < %d)))) AND n.nid != %d AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC, n.nid DESC'), $node->uid, $node->sticky, $node->sticky, $node->created, $node->created, $node->nid, $node->nid, 0, 1))) {
$links .= '<div class="prev">';
$links .= l(t('previous'), drupal_get_path_alias("node/".$prev->nid), array('title' => t('View the previous page.')));
$links .= '</div>';
$titles .= '<div class="prev">'. check_plain($prev->title) .'</div>';
}
else {
$links .= '<div class="prev"> </div>'; // Make an empty div to fill the space.
}
if ($next = db_fetch_object(db_query_range(db_rewrite_sql('SELECT n.nid, n.title FROM {node} n WHERE n.type = "blog" AND n.uid = %d AND (n.sticky > %d OR (n.sticky = %d AND (n.created > %d OR (n.created = %d AND n.nid > %d)))) AND n.nid != %d AND n.status = 1 ORDER BY n.sticky ASC, n.created ASC, n.nid ASC'), $node->uid, $node->sticky, $node->sticky, $node->created, $node->created, $node->nid, $node->nid, 0, 1))) {
$links .= '<div class="next">';
$links .= l(t('next'), drupal_get_path_alias("node/".$next->nid), array('title' => t('View the next page.')));
$links .= '</div>';
$titles .= '<div class="next">'. check_plain($next->title) .'</div>';
}
else {
$links .= '<div class="next"> </div>'; // Make an empty div to fill the space.
}
$links .= '<div class="up">';
$links .= l(t('up'), drupal_get_path_alias('blog/'. $node->uid), array('title' => t('View this page\'s parent section.')));
$links .= '</div>';
$output .= '<div class="nav">';
$output .= ' <div class="links">'. $links .'</div>';
$output .= ' <div class="titles">'. $titles .'</div>';
$output .= '</div>';
$output .= '</div>';
$node->body = $node->body.$output;
} else if($node->event_start && !$node->book) {
$output .= '<div class="book">';
if ($prev = db_fetch_object(db_query_range(db_rewrite_sql('SELECT n.nid, n.title
FROM {node} n
join {term_node} t on n.nid=t.nid
join {event} e on n.nid=e.nid
WHERE n.type = "'.$node->type.'" AND (e.event_start < %d OR (e.event_start = %d AND n.nid < %d)) AND n.nid != %d AND n.status = 1
ORDER BY e.event_start DESC, e.nid DESC'), $node->event_start, $node->event_start, $node->nid, $node->nid, 0, 1))) {
$links .= '<div class="prev">';
$links .= l(t('previous'), drupal_get_path_alias("node/".$prev->nid), array('title' => t('View the previous page.')));
$links .= '</div>';
$titles .= '<div class="prev">'. check_plain($prev->title) .'</div>';
}
else {
$links .= '<div class="prev"> </div>'; // Make an empty div to fill the space.
}
if ($next = db_fetch_object(db_query_range(db_rewrite_sql('SELECT n.nid, n.title
FROM {node} n
join {term_node} t on n.nid=t.nid
join {event} e on n.nid=e.nid
WHERE n.type = "'.$node->type.'" AND (e.event_start > %d OR (e.event_start = %d AND n.nid > %d)) AND n.nid != %d AND n.status = 1
ORDER BY e.event_start ASC, e.nid ASC'), $node->event_start, $node->event_start, $node->nid, $node->nid, 0, 1))) {
$links .= '<div class="next">';
$links .= l(t('next'), drupal_get_path_alias("node/".$next->nid), array('title' => t('View the next page.')));
$links .= '</div>';
$titles .= '<div class="next">'. check_plain($next->title) .'</div>';
}
else {
$links .= '<div class="next"> </div>'; // Make an empty div to fill the space.
}
$links .= '<div class="up">';
$links .= l(t('up'), drupal_get_path_alias('event/'.date("Y",$node->event_start).'/'.date("m",$node->event_start).'/'.date("d",$node->event_start).'/day'), array('title' => t('View this page\'s parent section.')));
$links .= '</div>';
$output .= '<div class="nav">';
$output .= ' <div class="links">'. $links .'</div>';
$output .= ' <div class="titles">'. $titles .'</div>';
$output .= '</div>';
$output .= '</div>';
$node->body = $node->body.$output;
} else if($node->type=='image' && !$node->book) {
$terms = taxonomy_node_get_terms_by_vocabulary($node->nid, _image_get_vid());
$p = array_pop($terms);
if($p->tid) {
$output .= '<div class="book">';
if ($prev = db_fetch_object(db_query("SELECT n.nid, n.title FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid = $p->tid AND (n.sticky < $node->sticky OR (n.sticky = $node->sticky AND (n.title < '".addslashes($node->title)."' OR (n.title = '".addslashes($node->title)."' AND n.nid < $node->nid)))) AND n.nid != $node->nid AND n.status = 1 ORDER BY n.sticky DESC, n.title DESC, n.nid DESC"))) {
$links .= '<div class="prev">';
$links .= l(t('previous'), drupal_get_path_alias("node/".$prev->nid), array('title' => t('View the previous page.')));
$links .= '</div>';
$titles .= '<div class="prev">'. check_plain($prev->title) .'</div>';
}
else {
$links .= '<div class="prev"> </div>'; // Make an empty div to fill the space.
}
if ($next = db_fetch_object(db_query("SELECT n.nid, n.title FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid = $p->tid AND (n.sticky < $node->sticky OR (n.sticky = $node->sticky AND (n.title > '".addslashes($node->title)."' OR (n.title = '".addslashes($node->title)."' AND n.nid < $node->nid)))) AND n.nid != $node->nid AND n.status = 1 ORDER BY n.sticky ASC, n.title ASC, n.nid ASC"))) {
$links .= '<div class="next">';
$links .= l(t('next'), drupal_get_path_alias("node/".$next->nid), array('title' => t('View the next page.')));
$links .= '</div>';
$titles .= '<div class="next">'. check_plain($next->title) .'</div>';
}
else {
$links .= '<div class="next"> </div>'; // Make an empty div to fill the space.
}
$links .= '<div class="up">';
$links .= l(t('up'), drupal_get_path_alias('taxonomy/term/'.$p->tid), array('title' => t('View this page\'s parent section.')));
$links .= '</div>';
$output .= '<div class="nav">';
$output .= ' <div class="links">'. $links .'</div>';
$output .= ' <div class="titles">'. $titles .'</div>';
$output .= '</div>';
$output .= '</div>';
$node->body = $node->body.$output;
}
}
return $node;
}
?>
Comments
Oooops
This code works with blogs also!
uninav_nodeapi function should be replaced with this code: