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

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

By Janet - June 17, 2008

Thanks! Here's the snippet that formats the records:

<!-- CONTENT: DIRECTORY PAGE TEMPLATE -->
<div id="page">
<div class="frame">
<div class="column1of2">
<p class="breadcrumb"><a href="index.php">Home</a> &raquo; Directories</p>
<?php
$facultyDirectory = "Directory Home";
if (isset($_GET['faculty_directory']))
{
$facultyDirectory = $_GET['faculty_directory'];
}
?>

<!-- full profile records 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 ?>
<?php echo $record['building_name'] ?>
<br />
<?php echo $record['university_name'] ?>
<br />
<?php echo $record['city_name'] ?>, <?php echo $record['state'] ?> <?php echo $record['zip'] ?>
</p>
<p class="contact">
<a href="mailto:<?php echo $record['email'] ?>">
<?php echo $record['email'] ?>
</a>
<br />
<?php echo $record['phone_number'] ?> (voice)
<br />
<?php echo $record['fax_number'] ?> (fax)
</p>
</div>
<?php endforeach ?>

<!-- here's the point where I'd like to say: if Adjunct Faculty, Courtesy Faculty, Conservation Faculty > then write this -->

<h2>
<?php echo $facultyDirectory ?>
</h2>

<?php foreach ($listRows as $record): ?>
<div class="directory-listing">
<h5>
<?php echo $record['fname'] ?> <?php echo $record['lname'] ?>
</h5>
<p class="locale">
<?php if ($record['title'] != ""): ?><?php echo $record['title'] ?><?php endif ?>
<a href="<?php echo $record['link_to_university'] ?>"><?php echo $record['university_name'] ?></a>
</p>
<p class="contact">
<a href="mailto:<?php echo $record['email'] ?>">
<?php echo $record['email'] ?>
</a>
<br />
<?php echo $record['phone_number'] ?> (voice)
</p>
</div>
<?php endforeach ?>

<?php if ($listDetails['prevPage']): ?>
<a href="<?php echo $listDetails['prevPageLink'] ?>">&lt;&lt; prev</a>
<?php else: ?>
&lt;&lt; prev
<?php endif ?>



<?php if ($listDetails['prevPage']): ?>
<a href="<?php echo $listDetails['prevPageLink'] ?>">&lt;&lt; prev</a>
<?php else: ?>
&lt;&lt; prev
<?php endif ?>

- page <?php echo $listDetails['page'] ?> of <?php echo $listDetails['totalPages'] ?> -

<?php if ($listDetails['nextPage']): ?>
<a href="<?php echo $listDetails['nextPageLink'] ?>">next &gt;&gt;</a>
<?php else: ?>
next &gt;&gt;
<?php endif ?>

</div>
<!-- faculty member list ends here -->


Ross has the details regarding the database, login, etc. if you want to look at the actual database set up.

Thanks SO MUCH! for your guidance and for the quickness of your replies.

Jan