Drupal Tutorials

Creating a community search page in Drupal with usernode, views and theming

It's assumed you are comfortable will creating views and basic theming.
This is a really quick tutorial in response to sahilr's question here: http://drupalsn.com/learn-drupal/drupal-questions/question-2470.

This tutorial outlines the procedures for Drupal 5 but if you are comfortable with Views 2 you can follow the tutorials principle and transfer it to Views 2 and it should work fine.

To create a page like the community page here on DrupalSN you will need:

A) Profile module

Enable the profile module and create some fields ie. favourite sport -> Football, rugby, cricket

B) Usernode

Download and enable the usernode module. This modules acts as a bridge between users and nodes so that we can use user details in views.
Theme/style your users in the list by creating a node-usernode.tpl.php file within your theme, here's an example of the content of this file:
<div class="usernode">
  <div class="picture">
    <?php echo l(theme('user_picture', $node), "user/$node->uid", array(), null, null, false, true); ?>
  <div class="details">
    <?php echo theme('username', $node); ?>
You may want to install imagecache to provide a thumbnail user picture.

C) Views

Download and install the views module, this is the real worker module in this setup.
  1. Create a new view, with a page view and set the:
    * page url to "community"
    * View Type to "teaser list"
    * Check the "Use Pager" box and select an appropiate amount for the Nodes per Page
  2. Now under filters select
    * Node:type "usernode"
    * Usernode:active "active"
    This makes sure we only select usernodes that are active accounting for any users who may have been blocked
  3. Next, still in the filters fieldset select the fields you want users to be able to search. (ie. Profile:favourite sport) Then for each field select "Is One Of" as the Operator and select all the listed values.
    Repeat for all the fields you want users to be able to search by.
  4. Now, next to each of your fields (in the filter fieldset) you should see an "Expose" button, click it and then scroll down to the "Exposed Filters" fieldset and check the following boxes:
    * Optional
    * Force Single
    * Lock Operation
    Exposed filters screenshot
    Again repeat this for each of your fields.
  5. Once last thing to complete the view, scroll to the bottom of the page and under "Sort Criteria" select field "Usernode: Created Time" and Order "Descending". This will make sure our newest members show at the top of our list.
  6. Save the view and it should be ready to go.
    If you don't like the filters on the view you could override their theme, see here http://drupal.org/node/220200 for more information.

As I said at the start it's only a quick tutorial but hopefully it has got you up and running.

Thanks for reading, comments welcome below.

Commenting on this Tutorial is closed.


Comments (1)

Thanks for the updates, i didn’t know all this.
Logo Design | Logo Designs | Business Logo | Website Design