Display X Nodes that are Promoted and Sticky

Last modified: March 4, 2008 - 21:43

This snippet was written to fulfill a need to have a frontpage that was easy to change. This snippet displays (X) nodes where the node has been marked as Promoted to frontpage AND is sticky.

<?php
/*
* [RPORT] This PHP snippet displays NODE-X where the node meets the criteria;
* n.promote = '1' - this is a node that is promoted to the front page AND;
* n.sticky = '1' - this is a node that is marked as sticky.
*/
$list_qty = 2;
$sql = "SELECT n.nid, n.vid, n.type, n.created, r.body, r.format FROM {node} n INNER JOIN {node_revisions} r ON r.vid = n.vid WHERE n.promote = '1' AND n.sticky = '1' ORDER BY n.created DESC";
      
$result = db_query_range(db_rewrite_sql($sql), 0, $list_qty);
      
while (
$node = db_fetch_object($result)) {
 
// print your markup here
 
print check_markup($node->body, $node->format, false);
}
?>

There is only one variable in use $list_qty = 2; that allows control how many nodes (X) to display that meet the criteria.

More Information

 
 

Drupal is a registered trademark of Dries Buytaert.