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
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
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.
interactivetools.com
Re: [Dave] One list page outputting different views depending on category?
By Janet - June 16, 2008
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
<?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! :)
interactivetools.com
Re: [Dave] One list page outputting different views depending on category?
By Janet - June 16, 2008
Thanks
Jan
Re: [Janet] One list page outputting different views depending on category?
By Janet - June 16, 2008
<?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
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!
interactivetools.com
Re: [Dave] One list page outputting different views depending on category?
By Janet - June 16, 2008
<?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
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?
interactivetools.com
Re: [Dave] One list page outputting different views depending on category?
By Janet - June 17, 2008
<!-- CONTENT: DIRECTORY PAGE TEMPLATE -->
<div id="page">
<div class="frame">
<div class="column1of2">
<p class="breadcrumb"><a href="index.php">Home</a> » 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'] ?>"><< prev</a>
<?php else: ?>
<< prev
<?php endif ?>
<?php if ($listDetails['prevPage']): ?>
<a href="<?php echo $listDetails['prevPageLink'] ?>"><< prev</a>
<?php else: ?>
<< prev
<?php endif ?>
- page <?php echo $listDetails['page'] ?> of <?php echo $listDetails['totalPages'] ?> -
<?php if ($listDetails['nextPage']): ?>
<a href="<?php echo $listDetails['nextPageLink'] ?>">next >></a>
<?php else: ?>
next >>
<?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