Member List customization using views module

LMNor - April 4, 2008 - 06:03

I understand, after talking to several members here, that I have to use CCK and Views to really customize a user profile the way I want and I have been reading up on how to use both. While that sounds simple enough it is slow going for me. There are no clear cut guides for what I want to do; most Views tutorials focus on tasks like creating an archive of previous blogs. While this will certainly be useful for my site once it has numerous blogs, at the moment it isn't particularly helpful to me trying to adapt a "how to make an archive view" into usable instructions on what I need to do which is customize a page to look differently than it currently does.

There is a fundamental difference to the way the two work. The tutorials for creating archive type lists/lists and tables, etc are for creating page types that do not exist out of the box. I need to modify pages that exist out of the box. I figure the best way to figure this out is to dive in with a simple modification of an existing page and go from there. Since CCK and the Bio Module will be required to do the profile modifications, I thought I'd try to do something a little easier as a start.

What I tried unsuccessfully to do and what I could use help with is using Views to change the way the member list is viewed. Currently, it is somewhat unformatted. I have made the members list page viewable by anon viewers in case anyone wants to go check out the current layout and/or help. View the current layout at http://www.tapbjj.com/profile.

What I need help with is:

  • 1. When creating this view, is it a page (when modifying an existing page)? If so, how do I determine the new page's URL? I assume that it has to be a page so that the pager can be used so people don't have to scroll through a list of several hundred members.
  • 2. For view type I am assuming that particularly in this case, it should be "Table View". Is that accurate? Once a table view is created, what governs the way the table is displayed? I am assuming it just inherits the properties out of style.css, but I am not 100% sure.
  • 3. For fields, I am assuming I should choose all the fields I want displayed out of the drop down list that start : "Profile: (Profile Field)". I don't however see a field for Profile: User Avatar, or something similar to that. Would I want to choose "User: Author Picture"?
  • 4. For arguments, I am actually fairly confused. From the views documentation, this is the aspect of views that is most difficult to understand (at least for me). I think I would choose ... scratch that... I have no clue what to choose. I vaguely understand how the arguments work when trying to make a page that filters something, i.e. if the user selected is the author, return any pages of a given type, but I have no clue how the arguments work when it is something like a member list that natively, as in how it appears on the out of the box drupal.domain/profile where there appears to be no argument and accessing the page returns a list of all members. Do I just ignore the arguments section all together?

    Now, to help me understand this better, what would be done differently if I wanted to add a small search function at the top of the members list that would allow you to sort members by their name? Is there a way to allow searchers to pull up profiles by the month/year they were created? My suspicion is that these features that should be implemented on another page all together rather than in the view I am trying to create to simply format the way the standard member list page is displayed. Am I correct in this assumption?

  • 5. Filters: I don't think filters would be used on a view that I am creating just to change the look of the standard member page. I think they would be used to create a page such as described in #4; however, I need to crawl before I walk, and at this point I'd settle for simply being able to roll over onto my belly LOL. So for the point of helping me understand this, am I correct that I don't need any filters for a view of this sort? If you have time or the desire, and want to describe what filter settings I would use to implement something like I described in #4 feel free to post it, but don't feel obligated, I will be happy with any answers that even vaguely point me in the right direction for any of these questions... a good understanding or thorough explanation would just be bonus :)
  • 6. Wow, I have already asked a lot, and I truly appreciate anyone who took the time to even read this far, but this is my last question, and possibly the most important: How do I get the standard member list page to use the new view I have created? From the way I understand it (and I could be totally wrong) I need to create a custom .tpl.php such as node-members.tpl.php which is in itself a source of confusion.

    Typically, I see custom tpl.phps in the form that indicates the type of node using the override. In this case, using what I usually see as formats, the custom tpl.php would be node-profile.tpl.php however, if I chose that as the name, what would I do when I start applying things to the actual individual user's profile pages? would this tpl.php automatically apply this view to those pages as well?

    Outside of the naming questions, the node-whatever.tpl.php should include divs to break up the content (at least this is my understanding). For this I would create div classes for each area such as "Personal Information" and "User Picture" as div classes and then specify their styles in style.css, is this accurate? Should stylings for a view such as what I am describing have predefined div sizes, such as 200px etc or would best practices dictate that I use a percentage such as 50%? Is Drupal smart enough to constrain the information that is supposed to go into those divs into whatever proportions I choose?

    Lastly, do I need to input code into the template.php to alert my theme to use this new view when the page, in this case www.drupalinstallation/profile, is called? What is the code I put in? Do I need a separate entry in template.php for each and every view that I want to apply?

    I fully understand if anyone who has actually taken the time to read this lengthy post (that clearly defines what a total Drupal noob I am) doesn't have time to answer everything, or even anything, but I would truly appreciate the help from anyone who does have the time. If there are good explanations already posted any links would be greatly appreciated (and would save you the time of typing out 'remedial Drupal' lessons to me :P ).

    I got into some trouble earlier in this 'journey' when I found some old posts on how to make profile changes using pure template.php overrides, style.css, and node-xxx.tpl.php overrides, and after spending a lot of time, I was informed that those posts were more or less outdated methods and that I should be using views to gain this effect. For this reason it is now hard for me to tell if the post I am reading is even a practice currently used, outdated/depreciated, or should be considered a "best practice". This is why I posted this long dissertation here, hoping for a little explanation from users familiar with views etc, and the possibility that I will get pointed in the right direction and successfully avoid finding outdated methods and learning 'bad habits' before I realize they are wrong.

    Thanks again for taking the time to read this and sorry it was soooooo long.

  • Here is what I have muttled

    LMNor - April 4, 2008 - 07:12

    Here is what I have muttled through (though it isn't working...go figure). It half worked and can be seen at http://www.tapbjj.com/profile. Basically, it lists admin numerous times (30+) and does not include many of the users

    Created a custom view for the memberlist:

    Page:
    name:memberlist_view
    selected provide as page view
    url: profile
    view type: table view

    Block:
    none

    Fields:
    Profile: Real Name
    Profile: Gender
    Profile: City
    Profile: State
    Profile: About Me
    User: Author Picture

    Arguments:
    none

    Filters:
    none

    Exposed Filters:
    none

    Sort Criteria:
    none

    I then added the following to template.php

    function _phptemplate_variables($hook, $vars = array()) {
      switch ($hook) {
        case 'node':
          $vars['template_files'] = array('node-'. $vars['nid']);
          break;
      }
      return $vars;
    }

    and created a custom node-profile.tpl.php containing the following lines:

    <?php
    //load the view by name
    $view = views_get_view('memberlist_view');
    //output the view
    print views_build_view('embed', $view);
    ?>

    I am close heh, I think... where did I go wrong?

    Digging a little deeper, it

    LMNor - April 4, 2008 - 08:00

    Digging a little deeper, it seems to be putting up a listing for each item submitted by a member. i.e. there are over 30 instances of admin because admin has submitted the majority of content on the site. The missing users are users who have not posted anything ever.

    What I need to figure out now is how to get it to list members, one time per member on the memberlist (.../profile) page based on the person being a registered member, not off submitted posts and certainly not an entry for each submitted post...

    The problem is that Views

    Mark Theunissen - April 4, 2008 - 12:15

    The problem is that Views does not support users. Views supports nodes, so you are correct in realising that it's giving you a list of the users that created all the nodes.

    View 2 (in alpha stages), does support views of users, but it's a little way off from completion!

    What you need to do, as I suggested in the previous thread, is install the Bio module. Then, you'll have a node for every user, and you can create a view of Bios, which will be the users...

    __________________________________________________________

    Mark Theunissen

    Code Baboon
    Drupal based services

    ah, ok so bio turns the

    LMNor - April 4, 2008 - 12:42

    ah, ok so bio turns the /user/* into a node which can then be turned into a view that mimics the current /profile node's functionality.

    Wow, and I thought I would try to start off with an easy one first and work my way up to the bios and cck. I am begining to think that there is no 'easy' one so I guess it's time to dive right in.

    Installing Bio, then trying to create a view that sums them all up. Quick question, can Bio module be used in conjunction with Usernode module? Usernode is a requirement of Buddylist2 which I was thinking of replacing Buddylist with.

    That's exactly what it does,

    Mark Theunissen - April 4, 2008 - 13:02

    That's exactly what it does, amoungst other things.

    Bio and usernode do very similar things, so my guess would be no you shouldn't use them together... but of course, you can use the Usernode module to build views of users! I just suggested Bio because I prefer it to Usernode and it has more features built in.
    __________________________________________________________

    Mark Theunissen

    Code Baboon
    Drupal based services

    Thanks Mark, I had usernode

    LMNor - April 4, 2008 - 13:26

    Thanks Mark, I had usernode uploaded already so I turned it on quick so I could edit my view while everything is fresh in my head, and it worked... doesn't look great but at least it's laid out correctly.

    I am adding the Bio module when I wake up later because it looks very nice from the picture, seems a bit more configurable, and well frankly you recomended it and have been right about everything else so far :)

    When I upload the bio mod I am going to go right into configuring profile pages. When I use CCK to add fields to profile pages can I create fields that users can choose on a per user basis to display? I would like to give them the option to hide their real name etc if they so desire? Also, if that is the case can i set the view to show those fields only if they are 'visable'?

    Lastly, can the views I made such as what is up on www.tapbjj.com/profile be further customized or am I stuck with the stock output of views? If they can be customized is there a thread that goes into how? I found one that sonded like it might be similar to what I am looking for, but it said it was only for themeing list mode views. Is there a way to apply style.css to it?

    Thanks again for your help, it is starting to make more sense now and I am now going to bed in a good mood for the first time since I started trying to customize this stuff!

    Thanks :)

    No prob :) You can configure

    Mark Theunissen - April 4, 2008 - 13:46

    No prob :)

    You can configure which CCK fields to display, I just do it manually in code because it's quick, but there's probably a module that does it... you'll have to look or ask around because I don't know offhand.

    Style.css will apply to your views... so yes, but to really change views, you need to theme them in template.php... search for theming views, should be plenty of info, but it is quite a mission from what I remember... ;)

    __________________________________________________________

    Mark Theunissen

    Code Baboon
    Drupal based services

     
     

    Drupal is a registered trademark of Dries Buytaert.