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

Creating a community search page in Drupal with usernode, views and 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:
Usernode module
Views module
Profile module (part of core)

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:

uid”, array(), null, null, false, true); ?>

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.
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
    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
    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.
    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.
    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.
    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.

Leave a Reply

Your email address will not be published. Required fields are marked *