Recent Topics – My First Drupal Mod

This site is developed on Drupal CMS. Today I though, I should show a block containing some recent posts like “Recent Comments” block. I searched for long for any module. but i did not get. later, I have developed my first mod for drupal to show some recent topics/contents/posts.

How to do it:

1. Login as admin
2. Goto Administrator -> Site Building -> Blocks
3. Click “add block” link from top.
4. Enter “Recent Topics” in block description box
5. Write the following code in the block description box. You may change $list_no to any value.
6. Choose PHP code from Input Format section. This will not work, until you choose (you must have to enable it if not enabled).
7. Click Save Block
8. After saving, you will be redirected to block list. Most probably, you block is listed under Disabled category. Now choose a region for your block. You may choose Left Sidebar or Right Sidebar.
9. After selecting, click Save Blocks.
10. Go your homepage. You should now see the the recent topics.

$list_no = 10;

$query = “SELECT n.nid, n.title FROM
{node} n WHERE n.status = 1 ORDER BY
n.created DESC LIMIT $list_no”;
$sql = db_rewrite_sql($query);
$result = db_query($sql);
$output .= l($node->title,”node/$node->nid”).’
print $output;