Category sidebars
10 posts by 3 authors in: Forums > CMS Builder
Last Post: July 16, 2008 (RSS)
By Janet - July 8, 2008
I'm trying to make it easy on my client by including special sidebars in one of the categories of my site. There's two sections in this category and each sidebar is specific to a section.
I thought I'd add a couple of sidebar fields to the category database and call those fields into the list and article pages. So far so good.... except both sidebars appear on each page. It looks like I've got to add more parameters into the code. If Undergraduate, then write this sidebar; if Graduate, then write this sidebar.
Here's my code so far:
<?php include ("/usr/www/uga/htdocs/dev/cmsAdmin/templateFiles/viewers/admissionsCategoriesListViewer.php"); ?>
<?php foreach ($listRows as $record): ?>
<?php if (!$record['hide_this_category_from_menu']): ?> //hides one of my categories
<h4><?php echo $record['sidebar_resource_header_a'] ?></h4>
<?php echo $record['sidebar_resourse_list_a'] ?>
<h4><?php echo $record['sidebar_resource_header_b'] ?></h4>
<?php echo $record['sidebar_resource_list_b'] ?>
<?php endif ?>
<?php endforeach ?>
I don't know how to write this PHP into the above context -
if ($type == 'Undergraduate'):
if ($type == 'Graduate'):
Here's the example in all it's duplicious glory: http://uga.edu/dev/ecology/admissionsList.php?category=Undergraduate
and http://uga.edu/dev/ecology/admissions.php?Article_One-1/
Can you help me?
Jan
Re: [Janet] Category sidebars
By Dave - July 8, 2008
Try this:
<?php foreach ($listRows as $record): ?>
<?php if (!$record['hide_this_category_from_menu']): ?> //hides one of my categories
<?php if ($record['type'] == 'Undergraduate'): ?>
<h4><?php echo $record['sidebar_resource_header_a'] ?></h4>
<?php echo $record['sidebar_resourse_list_a'] ?>
<?php endif ?>
<?php if ($record['type'] == 'Graduate'): ?>
<h4><?php echo $record['sidebar_resource_header_b'] ?></h4>
<?php echo $record['sidebar_resource_list_b'] ?>
<?php endif ?>
<?php endif ?>
<?php endforeach ?>
Hope that helps! :)
interactivetools.com
Re: [Dave] Category sidebars
By Janet - July 14, 2008
<!-- Record List-->
<?php
require_once "/usr/www/uga/htdocs/dev/cmsAdmin/lib/viewer_functions.php";
$options = array();
$options['tableName'] = 'admissions_resources';
$options['recordNum'] = '';
$options['where'] = '';
$record = getRecord($options);
?>
<!-- /Record List -->
<?php if ($record['category'] == 'Undergraduate'): ?>
<?php echo $record['content'] ?><br/>
<?php endif ?>
<?php if ($record['category'] == 'Graduate'): ?>
<?php echo $record['content'] ?><br/>
<?php endif ?>
<!-- /Record List -->
...it would work. And it does, sort of.... the results are a bit mixed.
The undergraduate list and article pages work great [http://uga.edu/dev/ecology/admissionsList.php?category=Undergraduate]
The graduate list page shows my undergraduate sidebar. The graduate article page doesn't show anything at all.
[http://uga.edu/dev/ecology/admissionsList.php?category=Graduate]
Bummer. So close... yet still so far away.
Jan
Re: [Janet] Category sidebars
By Dave - July 14, 2008
Is the 'admissions_resources' section a single record section or a list section?
The Graduate page seems to be showing content now. Did you get it figured out? If not can you let me know what part I should be looking for that's not working? Thanks! :)
interactivetools.com
Re: [Dave] Category sidebars
By Janet - July 14, 2008
The sidebar you see on the graduate page is actually the content from the undergraduate sidebar.
I hope that makes sense.
Jan
Re: [Janet] Category sidebars
By Dave - July 14, 2008
Can you email me CMS and FTP (I think I already have that) so I can take a closer look? My email is dave@interactivetools.com.
I have an idea but I think it will be quickest if I can just take a look at the admin sections first.
Thanks!
interactivetools.com
Re: [Dave] Category sidebars
By Janet - July 16, 2008
Here's the solution in a nutshell:
1. Admin > Section Editor > Create a section with your categories (Section Name: Cat A, Cat B). I named this section "Admissions" with Undergraduate and Graduate as my categories.
2. Admin > Section Editor > Create another section for your sidebars Add a field for [content] and a list field containing the categories listed above (Cat A, Cat B). I named my section editor "Admissions Resource List" and included a list field containing "Undergraduate" and "Graduate" as options.
Now my client can now create sidebars in the "Admissions Resource List" section and choose which category she'd like that sidebar to appear. The sidebar appears on both the category (List) page and the article pages.
Here's the code for the admissionList.php page. I put it in a right sidebar div tag (well, actually Dave did... thank you Dave):
<!-- STEP1: Load Record List (Paste this above other steps) -->
<?php
require_once "/usr/www/uga/htdocs/dev/cmsAdmin/lib/viewer_functions.php";
$options = array();
$options['tableName'] = 'your_section_name;
$escapedCategory = mysql_real_escape_string(@$_REQUEST['category']);
$options['where'] = "category = '$escapedCategory'";
$record = getRecord($options);
?>
<!-- /STEP1: Load Record List inside sidebar DIV tag -->
<?php echo $record['content'] ?>
Here's the code for admissionsPage.php (article pages). Instead of $_REQUEST['category'] use $record['category'] (or whatever variable holds the category name) instead. Like this:
$escapedCategory = mysql_real_escape_string(@$record['category']);
$options['where'] = "category = '$escapedCategory'"; :
<!-- STEP1 for article pages: Load Record List (Paste this above other steps) -->
<?php
require_once "/usr/www/uga/htdocs/dev/cmsAdmin/lib/viewer_functions.php";
$options = array();
$options['tableName'] = 'your_section_name';
$escapedCategory = mysql_real_escape_string(@$record['category']);
$options['where'] = "category = '$escapedCategory'";
$record = getRecord($options);
?>
<!-- /STEP1: Load Record List inside article page sidebar DIV -->
<?php echo $record['content'] ?><br/>
Worked like a charm!
Thanks again Dave,
Jan
Re: [Janet] Category sidebars
By kevbarker - July 16, 2008
Could you post a link to the site so that we can see the final result? That would be great if you could.
Thanks,
Kevin
Re: [kevbarker] Category sidebars
By Janet - July 16, 2008
I can't keep up with my content editor - I see she's already deleted my test articles but there's one or two up that will show you what we were trying to achieve.
Jan