All content types _except_ forum posts

Last modified: March 20, 2008 - 10:23

Place the following code in a block to display a list of all new content (newest on top) except forum posts. Posts do not move to the top when receiving replies, so each one appears on top of the list when created and when changed. The "More" link simply displays the "Recent posts" list (tracker) and can be omitted.

This is useful for example in combination with the Active Forum Topics block, so that forum posts are not displayed in both.

To adjust the number of posts shown, simply change the number at the second line (num_nodes = 5).

<?php
$num_nodes
= 5;

$result = db_query_range(db_rewrite_sql('SELECT n.nid, n.title, n.type
FROM {node} n
WHERE n.status = 1 AND n.type <> "forum"
ORDER BY n.changed DESC'
), 0, $num_nodes);

$output = node_title_list($result);
$output .= l('More...', 'tracker');

print
$output;
?>

Works as Page or Story Block in Drupal 6

swimswimswim - February 14, 2008 - 22:51

I hacked your code to make a Block of Stories and a Block of Pages.

Story Block

<?php
$num_nodes
= 5;

$result = db_query_range(db_rewrite_sql('SELECT n.nid, n.title, n.type
FROM {node} n
WHERE n.status = 1 AND n.type = "story"
ORDER BY n.changed DESC'
), 0, $num_nodes);

$output = node_title_list($result);

print
$output;
?>

Yes, this is only the five most recent stories, but it works for now.

Page Block

<?php
$num_nodes
= 10;

$result = db_query_range(db_rewrite_sql('SELECT n.nid, n.title, n.type
FROM {node} n
WHERE n.status = 1 AND n.type = "page"
ORDER BY n.changed DESC'
), 0, $num_nodes);

$output = node_title_list($result);

print
$output;
?>

This is assuming there aren't more than 10 pages.

Indeed these are some ugly hacks. I was unable to find a solution to display a Block of all content type Page (or Story or both). I do not know php to write my own.

DanielTheViking, thanks for posting the original php snippet.

Here's a block that shows

mypreferreduser... - October 14, 2008 - 15:57

Here's a block that shows the most recent 10 pages or stories:

<?php
$num_nodes
= 10;

$result = db_query_range(db_rewrite_sql('SELECT n.nid, n.title, n.type
FROM {node} n
WHERE n.status = 1 AND n.type = "story" OR n.type = "page"
ORDER BY n.changed DESC'
), 0, $num_nodes);

$output = node_title_list($result) . '&nbsp;&nbsp;<a href="tracker">more</a>';

print
$output;
?>

Slight adjustment?

DropSys - March 25, 2009 - 14:52

What do i need to write into this snippit to show d/m/y for each content coming from the tracker?

I imagine here i would add the date, no? > $output = node_title_list($result)

<?php
$num_nodes
= 10;

$result = db_query_range(db_rewrite_sql('SELECT n.nid, n.title, n.type
FROM {node} n
WHERE n.status = 1 AND n.type = "story" OR n.type = "page"
ORDER BY n.changed DESC'
), 0, $num_nodes);

$output = node_title_list($result) . '&nbsp;&nbsp;<a href="tracker">more</a>';

print
$output;
?>

Thank you.
DropSys

 
 

Drupal is a registered trademark of Dries Buytaert.