How to: Have a simple user list and search function
Posted: 15 February 2008 05:24 PM   [ Ignore ]
Member
Avatar
RankRankRank
Total Posts:  53
Joined  2007-07-16

I needed a simple user list and search function. I’m sure the SolSpace chaps are adding this to the User module at some point but in the mean time this should keep some folks happy…

uberism.net/stuff/pi.memberinfo.php.txt

It’s a plugin called memberinfo.php which I use for random little member based functions I need here and there (I’m pretty sure I posted this somewhere before but I’ve already forgotten where so here’s the latest version, in it’s own thread).

Here are some samples of how to use it:

memberExists - find out if a user exists (from a username)

{if "{exp:memberinfo:exists username="{segment_2}"}"}
Member exists
!
{/if}

_emptyBio - Returns bio with prefix (if it is not empty) - I had some trouble detecting if {bio} was empty or not which is why I added this

{exp:memberinfo:_emptybio before="About {screen_name}..." type="p" class="nobp nobm"}
{bio}
{
/exp:memberinfo:_emptybio}

getAge - users age from DOB

{exp:memberinfo:getage y="{bday_y}" m="{bday_m}" d="{bday_d}"/}

getList - with user

{exp:memberinfo:getList limit="10" cols="3" orderby="screen_name" sort="asc"}

{row}
<div class="member">
{if "{photo_filename}"}
<img src="/images/member_photos/{photo_filename}" width="96" height="96"/>
{/if}
<p><a href="#your_member_profile_url_format">{screen_name}</a>
</
div>
{/row}

<p>Members {from} to {to} of {total}</p>

<
p>{prev}</p>

<
p>{next}</p>

{/exp:memberinfo:getList}

getList - Can also return a list of users from a search field. Simplifed version:

Search page - Set this up with a text field and a button, point it to the same template that the form is in, but add a new segment on the end to tell the template it’s on a results page.
In this example, the form is set up in a template group called “my_members” and in a template called “search”.

<form name="membersearch" id="membersearch" method="post" action="/my_members/search/results">
<
fieldset>
<
input type="text" id="formusername" name="formusername" maxlength="50" value="" size="35"/>
<
input type="submit" name="submit" value="Do it" />
</
fieldset>
</
form>

Then, add your getList results to that same template, referencing the name of the field that is being submitted.
(This page would be “/my_members/search/results”, and that would be loaded after someone clicks submit)

{if segment_3}

{exp
:memberinfo:getList limit="10" cols="3" orderby="screen_name" sort="asc" search_field="formusername"}

<p>You searched for {searchterm}.</p>

{row}{screen_name}{/row}

{
/exp:memberinfo:getList}

{
/if}

The plugin is really something I’ve made for my own use but if anyone else can find it useful then good. It’s pretty easy to customise too smile

Enjoy wink

EDIT: Feb 18th:
* Fixed some pretty major flaws in the search code
* Added {searchterm} as a variable for the search results page.
* Download is still at: uberism.net/stuff/pi.memberinfo.php.txt

The working example of this is over at www.crawlofthedead.com/zombies/search

Profile
 
 
Posted: 16 February 2008 08:28 AM   [ Ignore ]   [ # 1 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  3256
Joined  2006-10-18

Tony,

You’ve outdone yourself again! LOL

Haha, thanks! smile

 Signature 
Profile
 
 
Posted: 18 February 2008 04:55 AM   [ Ignore ]   [ # 2 ]
Member
Avatar
RankRankRank
Total Posts:  53
Joined  2007-07-16

Updated smile

Profile