Blocks

Useful block snippets.

Drupal 7 Code Snippets for Blocks Pages

Sharing some of the code snippets related to Drupal 7. As you know that in Drupal 7 the API has changed and the SQL snippets that you used in Drupal 6 will no longer work in drupal 7. This was a big problem for me. This article will be useful if you dont know much coding, but can manage minor changes to code.

Displaying block on Front Page ONLY

I had a strange problem today. I wanted to show a block on homepage only. So I went to the Block and added "" and clicked the box "Show only on listed pages". You would think this should work. But when your website has "node" as front page and if you have 10 pages of Nodes, the block will show on all 10 pages and not just the home page

This is a weird problem, I tried many combinations, until I figured out that you have to put the following PHP Code and select "Show only if PHP code returns TRUE"

How-To: 

Tabbed Blocks

How do you creat tabbed blocks in Drupal ?

Eg on: http://stilbuero.de/jquery/tabs/#section-1

Check the solution on http://drupal.org/node/89338

How-To: 

Place blocks anywhere on the site

If you want to place blocks on a page or story or anywhere on your site , or on front page , here is a quick trick

Code for Recent Comments: Drupal 5

How-To: 

Top posters with total number of members

Displays Top posters with total number of members like on http://csqa.info

<?php $users = db_query("SELECT COUNT(nid) AS count, {users}.uid, {users}.name FROM {node} LEFT JOIN {users} ON {node}.uid = {users}.uid WHERE {node}.uid != 0 GROUP BY uid ORDER BY count DESC LIMIT 5");
while ($user = db_fetch_object($users)) {
print "uid."\">".$user->name."";
}
?>

<?php $users1 = db_query("SELECT Count(uid) as count1 from users");
while ($user1 = db_fetch_object($users1)) {
print "Total members: ".$user1->count1;
}
?>

How-To: 

Display joining date on Who's new block.

You will have to hack the user.module for this. So be careful while you upgrade.

Find this place at around line 570 in user.module (in function user_block):

<?php
case 2:
if (user_access('access content')) {
// Retrieve a list of new users who have subsequently accessed the site successfully.
$result = db_query_range('SELECT uid, name FROM {users} WHERE status != 0 AND access != 0 ORDER BY created DESC', 0, 5);
while ($account = db_fetch_object($result)) {
$items[] = $account;
}
$output = theme('user_list', $items);

How-To: 

Add Scrollbars in Blocks

You can add scrollbars to blocks and make all the blocks of the same size. It works on IE and Firefox.Here is how you do it.Open you theme stylesheet ( style.css ) & add following code:


div.inner {
}

div.outer {
height: 200px;
overflow-y: scroll;
}

This will add horizontal scroll bar. If you wish to enter a vertical scrollbar too.. add the following line.

div.outer {
height: 200px;
overflow-y: scroll;
overflow-x: scroll;
}

How-To: 
Subscribe to RSS - Blocks