Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Works as Page or Story Block in Drupal 6
I hacked your code to make a Block of Stories and a Block of Pages.
Story Block
Yes, this is only the five most recent stories, but it works for now.
Page Block
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
Here's a block that shows the most recent 10 pages or stories:
Slight adjustment?
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)
Thank you.
DropSys
Link to more content
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
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 )
Is there any way that this
Is there any way that this will display just the list, without the "more" bit?