Category sidebars

10 posts by 3 authors in: Forums > CMS Builder
Last Post: July 16, 2008   (RSS)

By Janet - July 8, 2008

Hi everyone -

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

Hi Jan,

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! :)
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Category sidebars

By Janet - July 14, 2008

Hi Dave - Great talking with you today. And thanks for getting back to me about my sidebar situation. I've chosen a different route which I think will be easier for my client to update. Instead of adding two fields to my category section editor, I've created a special section called "Admissions Resource List" with title, content and a choice of categories - "Undergraduate" and "Graduate." I thought that if I write this in both my admissions.php and my admissionsList.php pages:

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

Hi Janet,

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! :)
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Category sidebars

By Janet - July 14, 2008

It's a multi-page section. I thought I could create two articles in the section - one for the undergraduate admissions sidebar which should appear on all the undergraduate admission pages (this is the placeholder content: Mark your calendar-Undergraduate: / Helpful links - Undergraduate:); the other for the graduate admissions sidebar which should appear on the graduate admission pages (this is the placeholder content: Mark your calendar-Graduate: / Helpful links - Graduate:).

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

Hi Jan,

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!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Category sidebars

By Janet - July 16, 2008

Thanks so much Dave. Your solution worked perfectly. My client can now add content to sidebars that appear on both the category list page and all the articles within that category. PLUS she can write separate sidebars based on the category.

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

Jan,

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: [Janet] Category sidebars

By kevbarker - July 16, 2008

Thanks! Nice site!

Kevin