One list page outputting different views depending on category?

12 posts by 2 authors in: Forums > CMS Builder
Last Post: June 18, 2008   (RSS)

By Janet - June 16, 2008 - edited: June 16, 2008

I'm setting up a directory section for my site. The client requested 5 categories, one for each member group. Easy-peasy. I set up a directoryList.php calling the list viewer and BAM! I got 5 separate directory pages that contained the contact info and profile links for each of the groups. I should have known it wasn't going to be that easy. Now they want to change the layout for two member groups so their directory listing page contain only some of the contact info.

Is there a way I can do this using the same directoryList.php? I've tried a few if/then iterations but no luck.

Here's a snippet of my code:

<!-- Faculty list starts here -->
<?php include ("/usr/www/uga/htdocs/dev/cmsAdmin/templateFiles/viewers/facultyMemberListViewer.php"); ?>
<h2><?php echo $facultyDirectory ?></h2>
<?php foreach ($listRows as $record): ?>
<div class="directory-listing"><a href="<?php echo $record['_link'] ?>">
<h5><?php echo $record['fname'] ?> <?php echo $record['lname'] ?></h5></a>
<p class="locale">
<?php if ($record['room_number'] != ""): ?> Room <?php echo $record['room_number'] ?>,<?php endif ?>
</div>
<?php endforeach ?>

What I'd love is:


<?php include ("/usr/www/uga/htdocs/dev/cmsAdmin/templateFiles/viewers/facultyMemberListViewer.php"); ?>

<!-- If regular faculty, then this -->
<h2><?php echo $facultyDirectory ?></h2>
<?php foreach ($listRows as $record): ?>
<div class="directory-listing"><a href="<?php echo $record['_link'] ?>">
<h5><?php echo $record['fname'] ?> <?php echo $record['lname'] ?>
</h5>
</a>
<p class="locale">
<?php if ($record['room_number'] != ""): ?> Room <?php echo $record['room_number'] ?>,<?php endif ?>
</div>
<?php endforeach ?>

(if retired faculty, then this)

<!-- Retired faculty -->

<h2><?php echo $facultyDirectory ?></h2>
<?php foreach ($listRows as $record): ?>
<div class="directory-listing"><a href="<?php echo $record['_link'] ?>">
<h5><?php echo $record['fname'] ?> <?php echo $record['lname'] ?>
</h5>
</a>
</div>
<?php endforeach ?>

Is there some kind of magic code I can use to make this possible?

Jan

Re: [Janet] One list page outputting different views depending on category?

By Dave - June 16, 2008

Hi Jan,

No problem, we can help! :)

So do you want both types listed on the same page? The regular faculties at the top and the retired faculties at the bottom?

If so, just create a field that indicates what kind of faculty it is, copy and paste the < ... foreach ... > block twice, and add this line (in red):

<h2>Regular Faculty</h2>
<?php foreach ($listRows as $record): ?>
<?php if ($record['type'] != 'regular') { continue; } ?>
...
<?php endforeach ?>

<h2>Retired Faculty</h2>
<?php foreach ($listRows as $record): ?>
<?php if ($record['type'] != 'retired') { continue; } ?>
...
<?php endforeach ?>


Let me know if that helps, or if you are trying to do something different.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] One list page outputting different views depending on category?

By Janet - June 16, 2008

Thanks for the fast response, Dave. My client would like each type listed on separate directory pages. The directory page for regular faculty includes six contact information fields with fname and lname linking to their profile page. The directory page for retired faculty includes just four of the six contact information fields. They don't have profiles.

Jan
(I'm saving this post, though. Bet I'll need it later.)

Re: [Janet] One list page outputting different views depending on category?

By Dave - June 16, 2008

Ok, do both the listings on the list page and the detail pages need to be different? If you have a field called 'type' you can display or not display fields for certain types with this code:

<?php if ($record['type'] == 'retired'): ?>
Only show this for retired
<?php endif ?>

I'm not totally clear how you want it to work. If that doesn't do it feel free to post an url to a mockup and I can take a look.

Hope that helps! :)
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] One list page outputting different views depending on category?

By Janet - June 16, 2008

This looks like it - I'll give it a try and will let you know. Thanks!...and please throw a "Hello" Ross's way. He developed most of the site (http://uga.edu/dev/ecology/index.php). I jumped in toward the middle so I could learn CMS Builder. (I let him do all the hard stuff.) And my client is just loving how easy it is to build all the content into the pages. A beautiful program, Dave.

Thanks
Jan

Re: [Janet] One list page outputting different views depending on category?

By Janet - June 16, 2008

Sorry - got a quickie question. How do I include multiple categories. Can I do it this way?

<?php if ($record['type'] == 'retired', 'adjunct faculty', 'courtesy faculty'): ?>
Only show this
<?php endif ?>

Will this work? I'm obviously PHP challenged....

Jan

Re: [Janet] One list page outputting different views depending on category?

By Dave - June 16, 2008

Hi Jan,

You can use 'or' and 'and'. Try this:

<?php if ($record['type'] == 'retired' or $record['type'] == 'adjunct faculty' or $record['type'] == 'courtesy faculty'): ?>
Only show this
<?php endif ?>

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] One list page outputting different views depending on category?

By Janet - June 16, 2008

The field that lists each category is called "faculty_directory" so I wrote:

<?php if ($record['faculty_directory'] == 'Regular Faculty' or $record['faculty_directory'] == 'Retired Faculty' or $record['faculty_directory'] == 'Administrative Staff' or $record['faculty_directory'] == 'Research Staff' or $record['faculty_directory'] == 'Postdoctoral Associates' or $record['faculty_directory'] == 'Graduate Students'): ?>

and I got "Notice: Undefined index: faculty_directory in /usr/www/uga/htdocs/dev/ecology/directoryList.php on line 62"

I did try ($record['type'] but got the same message.

After rereading your posts, you mentioned that my field should be called "type" Is that literal? If so, if I go back and replace my field name from "faculty_directory" to "type" will that mess up the records already put into the database?

I remain PHP challenged (but nonetheless learning everyday),

Jan

Re: [Janet] One list page outputting different views depending on category?

By Dave - June 16, 2008

Hi Jan,

It doesn't need to be called 'type' but the $record variable should be whatever the variable is that is already in your code.

Do you want to attach the directoryList.php so I can take a look for you?
Dave Edis - Senior Developer
interactivetools.com