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: [Jason] Formating Category levels in different font styles

By Mikey - November 5, 2010 - edited: November 5, 2010

Hey Jason, this works great! Thanks a ton for the solution.

So now I'm trying to wrap the <?php if and else with links that are generated using a text field called "web_link". Here are details on what I'm trying to achieve. This code is going to be used on a category list page for listing permits, licenses, fees involved for each listing. Some of the parent and sibling categories need links to other websites and/or documents that can be downloaded. Other parent and sibling categories do not get links at all... there's only a price associated with the listing.

The purpose of the "web_link" text field (as seen in the attached snap shot: cms-category-section.jpg) is to allow the client the ability to apply a link to a parent or sibling category if one is needed, otherwise no link is provided and no link appears on the page.

However with the code that I have shown below if no link is provided in the "web_link" text field, there is still a link that goes to the same page the list is on... it links to its self. I need to make the links appear on the site page if the link exist in the "web_link" text field, otherwise no link appears on the site page. I've provided a snap shot (categories-with-links.jpg) of the site page so you can see what I'm talking about. Some parent and siblings have links (colored yellow), others should not have link (colord pink)... but still do with the code below.

You may notice in the snap shot the last parent category is named with sibling... it's a typo and should have been named "Marriage transcripts - parent with link".

PS: the Horizontal Line check box is to allow me to separate the categories with a <hr/> ... just in case you're wonder what it does.

Any suggestions how I can make this work? I hope I explained this well.
Thanks for any light you can shed on this,
Zick

// load records
list($list_of_servicesRecords, $list_of_servicesMetaData) = getCategories(array(
'tableName' => 'list_of_services',
));
?>




<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"><a href="<?php echo $record['web_link'];?>" target="_blank"><?php echo $record['name'];?></a></span>

<?php elseif($record['depth']==1): ?>
<span class="servicesSibling"><a href="<?php echo $record['web_link'];?>" target="_blank"><?php echo $record['name'];?></a></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>

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

By Mikey - November 8, 2010

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