Display list of (x) recent posts (titles) snippet
Task · How to display a list of recent posts · Themers · Drupal 4.5.x or older · Drupal 4.6.x · Drupal 4.7.x · Drupal 5.x
Last modified: August 26, 2009 - 22:57
PLEASE NOTE! These snippets are user submitted. It is impossible to check them all, so please use at your own risk! For users who have setup drupal using an alternate database to the default (MYSQL), please note that the snippets may contain some database queries specific to MYSQL.
Description
This php snippet displays a list of the (x) most recent posts by the user and a links to the full nodes.
Dependencies: none.
Usage
- For use in your user profile page override
- Using a text editor like NOTEPAD.EXE or an equivalent, copy and paste the code into your user_profile.tpl.php file
- To increase/decrease the number of posts listed change the
$nlimitvalue to suit. The default setting is 5. - Change the div class names or the prefix text to suit.
<div class="fields">
<p>Recent Posts</p>
<?php
$output = '';
$uid = arg(1);
$nlimit = 5;
$result = db_query_range(db_rewrite_sql("SELECT n.created, n.title, n.nid, n.changed FROM {node} n WHERE n.uid = %d AND n.status = 1 ORDER BY n.changed DESC"), $uid, 0, $nlimit);
$output .= '<div class="item-list"><ul>' . "\n";
$output .= node_title_list($result);
$output .= '</ul></div>';
print $output;
?>
</div>
Has something gone wrong in the reorganisation?
It seems illogical that this snippet should be stored under "customizing user profile" - it is a general block snippet... When looking at the other things in this book section, it seems that many things are seriously misplaced.
Edit: I just moved it in under the "Drupal 5.x page snippets" chapter.
This shows recent posts by
This shows recent posts by the user. It should be stored in the user profile section.
Ah, could not re-save it before a reply was made...
I just moved it back, tried to edit with this comment:
Edit: It is not misplaced, I was not reading it carefully enough and only paid attention to my own need for the code... Sorry about that.
However, I think parts of this posts may also be relevant for page snippets.
I wish it was possible to use some of the book chapters as multiple-select categories, so it would be possible to tag snippets with several such categories. In this case; both with drupal version numbers, "php page snippet" and "customizing user profile".
What is the best way to do
What is the best way to do this in D6?
Currently, I'm experimenting with the use of Views in user profiles.
Please consider joining my site: http://www.getlives.com
Thank you. -GetLives
Is there any way to do what
Is there any way to do what you are doing here, but with nodes authored by that user only, instead of all posts? I am running version 6. Thank you!
http://8th-circuit.com