Recent weblog entries (titles) snippet

Last modified: April 6, 2007 - 19:34

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 $nlimit value in the first line of the snippet to suit.
  • Change the div class names or the prefix text to suit.

<?php
$nlimit
= 10;
$userid=$user->uid;
$query= "SELECT n.created, n.title, n.nid, n.changed FROM node n WHERE n.uid = $userid AND n.status = 1 ORDER BY n.changed DESC";
$result = db_query_range($query,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;
$userid=$user->uid;
$query= "SELECT n.created, n.title, n.nid, n.changed FROM node n WHERE n.uid = $userid AND n.status = 1 ORDER BY n.changed DESC";
$result = db_query_range($query,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:

<?php
global $user;
$nlimit = 10;
$query= "SELECT n.created, n.title, n.nid, n.changed FROM node n WHERE n.uid = $userid AND n.status = 1 ORDER BY n.changed DESC";
$result = db_query_range($query,0,$nlimit);
$list = node_title_list($result);
$output = '<h2>Latest Posts:</h2>';
$output .= strip_tags($list) ? $list : 'No Blog Postings available';
return
$output;
?>

This actually shows all

mike.hobo - November 27, 2007 - 23:39

This actually shows all content posted, like storys, blog and audio or whatever else you have.

to have it specific due this

<?php
$nlimit
= 10;
$userid=$user->uid;
$query= "SELECT n.created, n.title, n.nid, n.changed FROM node n WHERE n.uid = $userid AND n.type = 'blog' AND n.status = 1 ORDER BY n.changed DESC";
$result = db_query_range($query,0,$nlimit);
$output .= "<div class=\"item-list\"><ul>\n";
$output .= node_title_list($result);
$output .= "</ul></div>";
print
$output; ?>

I added AND n.type = 'blog' to the WHERE part.

 
 

Drupal is a registered trademark of Dries Buytaert.