/ Published in: PHP
simple node paging snippet
Expand |
Embed | Plain Text
<?php // Previous/Next node paging by title // See http://2bits.com for details. // Add this function to the end of the template.php of your theme function phptemplate_prev_next($current_node = NULL, $op = 'p') { // Node types to include in paging if ($op == 'p') { $sql_op = '<'; $order = 'DESC'; } elseif ($op == 'n') { $sql_op = '>'; $order = 'ASC'; } else { return NULL; } $output = NULL; foreach($node_types as $type) { $quoted_types[] = "'" . $type . "'"; } $sql = "SELECT nid, title FROM {node} n WHERE nid $sql_op %d AND status = 1 ORDER BY nid $order LIMIT 1"; $result = db_query($sql, $current_node->nid, $type); $data = db_fetch_object($result); return NULL; } } ?> <!-- Node paging start. Add this to your node.tpl.php and/or node-TYPE.tpl.php --> <?php if (!$teaser) : ?> <div class="navpn"> <div class="pnlaquo">«</div> <div class="pnraquo">»</div> </div> <?php endif; ?> <!-- Node paging end --> /* Add this to your style.css file */ .navpn { width: 500px; margin: 0 auto 0 auto; clear: both; display: block; text-align: center; line-height: 1.5em; } #pnprev { display: block; float: left; text-align: right; width: 200px; white-space: normal; word-wrap: break-word; padding: 0; } .navpn #pnmain { float: left; text-align: center; display: inline; padding: 0 1em 0 1em; } #pnnext { display: block; float: left; text-align: left; width: 200px; white-space: normal; word-wrap: break-word; padding: 0; } .pnlaquo { float: left; width: 10px; } .pnraquo { float: right; width: 10px; }
You need to login to post a comment.
