Community Documentation

Example: My Recent Posts Block

Last updated July 17, 2007. Created by bdragon on May 1, 2007.
Edited by add1sun. Log in to edit this page.

This example creates a block that, once enabled, will display a list of recent posts by the user profile who's profile you are currently viewing.

Add a view

Goto: http://example.com/admin/build/views/add
Then enter the following values.

Basic Information

Name: user_posts

Block

Check Provide Block.
View Type: List View
Title: My Recent Posts
Nodes per Block: 10

Fields

Add Field: Node: Title

Arguments

Add Argument: User: UID is Author

Argument Handling Code

Argument Code: But don't include the <?php ?> tags. This is the working and tested Drupal 5.1 code, but a previous comment makes me believe that replacing $type with $view['type'] should cause the code to work with older versions.

<?php
$args
;
if (
 
$type == 'block' &&
 
arg(0) == 'user' &&
 
is_numeric(arg(1))
) {
   
$args[0] = arg(1); // (user/# == arg(0)/arg(1))
}
return
$args; // Remember to return $args
?>

Filters

Add Filter: Node: Published

Sort Criteria

Add criteria: Node: Created Time with Order=Descending

Save

Enable the block you just created

If you've posted content, view your user page

About this page

Drupal version
Drupal 5.x

Reference

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.