Recent weblog entries (titles) snippet
Task · place latest blog posts with user profile page · theme user profile page · Developers and coders · Themers · Drupal 4.5.x or older · Drupal 4.6.x · Drupal 4.7.x · Drupal 5.x
Last modified: September 26, 2009 - 11:09
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 weblog titles and links to the full blogs
Dependencies: blog.module must be enabled.
Thanks to Thinkinkless and Incidental for help with improving this snippet!
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 weblog titles listed change the
$nlimitvalue in the first line of the snippet to suit. - Change the div class names or the prefix text to suit.
<?php
$nlimit = 10;
$query= "SELECT n.created, n.title, n.nid, n.changed FROM {node} n WHERE n.uid = %d AND n.type = 'blog' AND n.status = 1 ORDER BY n.changed DESC";
$result = db_query_range(db_rewrite_sql($query), $account->uid, 0, $nlimit);
$output .= "<div class=\"item-list\"><ul>\n";
$output .= node_title_list($result);
$output .= "</ul></div>";
print $output; ?>Only show if there are blog entries
This is for user_profile.tpl.php:
<?php
$nlimit = 10;
$query= "SELECT n.created, n.title, n.nid, n.changed FROM {node} n WHERE n.uid = %d AND n.type = 'blog' AND n.status = 1 ORDER BY n.changed DESC";
$result = db_query_range(db_rewrite_sql($query), $account->uid, 0, $nlimit);
$output .= "<div class=\"item-list\"><ul>\n";
$list = node_title_list($result);
$output .= strip_tags($list) ? $list : 'No Blog Postings available';
$output .= "</ul></div>";
print $output;
?>You can put this in a regular page set to php input filter, to display recent blog entries by the current logged in user:
<?php
global $user;
$nlimit = 10;
$query = "SELECT n.created, n.title, n.nid, n.changed FROM {node} n WHERE n.uid = %d AND n.type = 'blog' AND n.status = 1 ORDER BY n.changed DESC";
$result = db_query_range(db_rewrite_sql($query), $user->uid, 0, $nlimit);
$list = node_title_list($result);
$output = '<h2>Latest Posts:</h2>';
$output .= strip_tags($list) ? $list : 'No Blog Postings available';
return $output;
?>