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

Link to more content

mwangikamauj - November 13, 2009 - 06:25

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.

Sounds like AJAX functionality

DanielTheViking - November 16, 2009 - 10:15

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

 
 

Drupal is a registered trademark of Dries Buytaert.