Formating Category levels in different font styles

5 posts by 2 authors in: Forums > CMS Builder
Last Post: November 8, 2010   (RSS)

By Mikey - November 4, 2010

I've trying to apply two different font styles to two levels of categories. I want to make my top level category <h1> and my second level category <h2>. So I was going to try using this bit of code to split out the top level category so I could apply the <h1> to it with it effecting the second level category's need to be <h2>.

You can see in the block of code called "//get top level category and apply h1 style" and "//get second level category and apply h2 style" that I have added the code $tmpCat = "categoryFormat" => "onelevel"; and $tmpSCat = "categoryFormat" => "twolevel"; to try and split the top level category from the second level category. Can someone offer up any ideas how to get this working so I can split the categories using this bit of code... or if you have any better suggestions, I'm all ears. Using categories is still a bit fuzzy to me.

// load records
list($list_of_servicesRecords, $list_of_servicesMetaData) = getRecords(array(
'tableName' => 'list_of_services',
//'categoryFormat' => 'showall', // showall, onelevel, twolevel
));

//get top level category and apply h1 style
$topcat=array();
foreach($list_of_servicesRecords as $record){
$tmpCat = $record['name'];
$tmpCat = "categoryFormat" => "onelevel";
$topcat[$tmpCat]=$tmpCat;
}

//get second level category and apply h2 style
$seccat=array();
foreach($list_of_servicesRecords as $record){
$tmpSCat = $record['name'];
$tmpSCat = "categoryFormat" => "twolevel";
$seccat[$tmpSCat]=$tmpSCat;
}



<?php foreach($topcat as $topcat):?>
<h1><option value="<?php echo $topcat;?>"><?php echo $topcat;?></option></h1>
<?php endforeach ?>



<?php foreach ($list_of_servicesRecords as $record): ?>
<table border="0" cellpadding="0" cellspacing="0" class="tables">
<tr class="cell-border">
<td valign="top">
<?php foreach($seccat as $seccat):?>
<h2><option value="<?php echo $seccat;?>"><?php echo $seccat;?></option></h2>
<?php endforeach ?>

<p><?php echo $record['content'] ?></p>
</td>
<td width="100" valign="top" nowrap="nowrap"><?php echo $record['resident_fee'] ?></td>
<td width="100" valign="top" nowrap="nowrap"><?php echo $record['non_resident_fee'] ?></td>
</tr>
</table>
<?php endforeach ?>

Re: [zick] Formating Category levels in different font styles

By Jason - November 5, 2010

Hi Zick,

I took a look at your code and noticed a couple of things. First, to use the categoryFormat option, you need to use the getCategories function, not getRecords. Also, you can't use header tags on <option>'s, however, you can set the style attribute.

If you use getCategories function, you get a field called depth, which tells you what level that record is on: 0 is top level, 1 is 2nd level, etc.

Try this:
First get your records like this:
// load records
list($list_of_servicesRecords, $list_of_servicesMetaData) = getCategories(array(
'tableName' => 'list_of_services',
));


Next output your select options like this:

<select name="categories">
<?php foreach ($list_of_servicesRecords as $record): ?>
<?php if($record['depth']==0): ?>
<option value="<?php echo $record['name'];?>" style="font-size:20;font-weight:bold;"><?php echo $record['name'];?></option>
<?php elseif($record['depth']==1): ?>
<option value="<?php echo $record['name'];?>" style="font-size:15;font-weight:bold;"><?php echo $record['name'];?></option>
<?php else: ?>
<option value="<?php echo $record['name'];?>"><?php echo $record['name'];?></option>
<?php endif ?>
<?php endforeach ?>
</select>


This will make top level categories font-size 20 and bold, second level categories font-size 15 and bold, and everything else regular.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [zick] Formating Category levels in different font styles

By Jason - November 8, 2010 - edited: November 8, 2010

Hi Zick,

You need to do a check inside your <?php if ?> to check if there is a value inside web_link.

It would look like this:

<div id="page-content">
<?php foreach ($list_of_servicesRecords as $record): ?>
<?php echo $record['line'] ?>
<div id="list-services">

<?php if($record['depth']==0): ?>
<span class="servicesParent">
<?php if($record['web_link']):?> <a href="<?php echo $record['web_link'];?>" target="_blank"><?php endif ?>
<?php echo $record['name'];?>
<?php if($record['web_link']):?></a><?php endif ?>
</span>

<?php elseif($record['depth']==1): ?>
<span class="servicesSibling">
<?php if($record['web_link']):?><a href="<?php echo $record['web_link'];?>" target="_blank"><?php endif ?>
<?php echo $record['name'];?>
<?php if($record['web_link']):?> </a><?php endif ?>
</span>

<?php else: ?>
<span class="servicesSibling"><?php echo $record['name'];?></span>
<?php endif ?>

<span class="Resident"><?php echo $record['resident_fee'] ?></span>
<!-- /list-services --></div>

<span class="NonResident"><?php echo $record['non_resident_fee'] ?></span><br />
<div id="list-content"><span class="servicesContent"><?php echo $record['content'] ?></span>
<!-- /list-content --></div>

<?php endforeach ?>
<!-- /page-content --></div>


Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Formating Category levels in different font styles

By Mikey - November 8, 2010

Awesome!
Works like a charm.
Thanks Jason!!!!