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;
?>

Comments

swimswimswim’s picture

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.

mochi’s picture

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;
?>
DropSys’s picture

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

mwangikamauj’s picture

I am still learning how drupal works exactly. I have followed this example but I cannot get it to work for me. So far, I am able to display two nodes from the database with a more... link showing at the bottom of the node titles. I would link a situation where if a user clicks the more... link, extra node titles are fetched from the database and displayed in the main content area.
How do I rewrite the code to get me the extra content from the database. How exactly should the function pointed by the q parameter be like.
Any help on this will be highly appreciated.

Leeteq’s picture

I think there are some AJAX code examples elsewhere on this site for such functionality.

.
--
( Evaluating the long-term route for Drupal 7.x via BackdropCMS at https://www.CMX.zone )

Symbol’s picture

Is there any way that this will display just the list, without the "more" bit?