Sub-categories Tutorial

134 posts by 17 authors in: Forums > CMS Builder
Last Post: August 7, 2012   (RSS)

By Jason - July 21, 2010

Hi,

First, to get rid of the errors you're having on the page, on lines 123,124, and 125, replace the variable $record with $articlesRecord.

Next, if you want the links to go to articulo.php instead of the current detail page, change your links to this (I've highlighted the changes in red):

<a href="articulo.php?category=<?php echo $category['num']?>">

You'll need to make those changes in a few places. Give that a try and let me know if you run into any issues.

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] Sub-categories Tutorial

By svsanchez - July 21, 2010

Thank you Jason, now I only need to put in BOLD the selected subcategory in that same page (articulos-details.php). For example if you go to http://www.casahermes.com/articulos-details.php?Ej-techos-fibrocemento-1 you will see that only the first level menu has in BOLD the selected category ("TECHOS") but the selected subcategory ("FIBROCEMENTO") is not in bold. Here's the php code of the page:

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php


// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/home/casahem/public_html/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// load records

list($categoryRecords, $selectedCategory) = getCategories(array( 'tableName' => 'categories', 'categoryFormat' => 'twolevel', ));
list($articlesRecords, $articlesMetaData) = getRecords(array(
'tableName' => 'articles',
));

list($articlesRecords, $articlesMetaData) = getRecords(array(
'tableName' => 'articles',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$articlesRecord = @$articlesRecords[0]; // get first record

// show error message if no matching record is found
if (!$articlesRecord) {
header("HTTP/1.0 404 Not Found");
print "Record not found!";
exit;
}

?>


<html>

<head>
<meta http-equiv="Content-Language" content="es-gt">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>$articlesRecord['title'] - Casa Hermes Guatemala</title>
</head>

<body bgcolor="#333333" topmargin="0" leftmargin="0" link="#F64B00" vlink="#F64B00">

<table border="0" cellpadding="2" cellspacing="0" width="1000" id="table1" bgcolor="#FFFFFF">
<tr>
<td width="173">
<p align="center">
<img border="0" src="../images/index.1.jpg" width="150" height="149"></td>
<td>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" width="728" id="table5" height="90" bgcolor="#F64B00" bordercolor="#000080">
<tr>
<td>
<p align="center">BANNER 728x90</td>
</tr>
</table>
</div>
<p align="right"><b><font face="Tahoma" size="2" color="#000080">Inicio&nbsp;
|&nbsp; Qui?es Somos&nbsp;&nbsp; |&nbsp;&nbsp; Contacto&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</font></b></td>
</tr>
</table>
<table border="0" cellpadding="5" cellspacing="0" width="1000" id="table3" bgcolor="#FFFFFF">
<tr>
<td width="175" valign="top" style="border-right: 1px dotted #808080">
<p>


<font face="Tahoma" size="2">


<?php $selectedCat=""; ?> <?php foreach($categoryRecords as $category):?> <?php if(!$category['_hasParent']):?> <!--<?php echo $category['_listItemStart']; ?>--> <?php if($category['_isSelectedBranch']){echo "<b>"; $selectedCat=$category['num'];} ?> <a href="articulos.php?category=<?php echo $category['num']?>"><?php echo $category['name']; ?></a> <?php if($category['_isSelectedBranch']){echo "</b>";} ?> <!--<?php echo $category['_listItemEnd']; ?>--> <?php endif ?>
</font> <p> <font face="Tahoma" size="2"> <?php endforeach ?>



</font>



</p>
<p align="center"><b><font face="Tahoma" size="2" color="#666666">
--------------------------</font></b></p>
<form method="POST" action="--WEBBOT-SELF--" onSubmit="">
<!--webbot bot="SaveResults" U-File="../_private/form_results.csv" S-Format="TEXT/CSV" S-Label-Fields="TRUE" startspan --><input TYPE="hidden" NAME="VTI-GROUP" VALUE="0"><!--webbot bot="SaveResults" i-checksum="43374" endspan -->
<p><b><font face="Tahoma" size="2" color="#808080">Buscar:</font><font face="Tahoma" size="2" color="#666666"><br>
</font></b><input type="text" name="T1" size="17">
<input type="submit" value="Ok" name="B1" style="font-family: Tahoma; font-size: 10pt; color: #FFFFFF; background-color: #01009E"></p>
</form>
</td>
<td width="175" valign="top">


<font face="Tahoma" size="2">


<?php if($selectedCat): ?> <?php foreach($categoryRecords as $category): ?> <?php if ($selectedCat==$category['parentNum']):?> <!--<?php echo $category['_listItemStart']; ?>--> <a href="articulos.php?category=<?php echo $category['num']?>"> <?php echo $category['name']; ?> </a> <!--<?php echo $category['_listItemEnd']; ?>--> <?php endif ?> <p> <?php endforeach ?> <?php endif ?>


</font>


</td>
<td width="650" valign="top">



<font face="Arial" size="2"><font color="#666666">











</font></font><b>
<font face="Arial" size="4" color="#000080"> <?php echo $articlesRecord['title'] ?></font></b><font face="Arial" size="2" color="#666666"><br/>
<?php echo $articlesRecord['content'] ?><br/>
_link : <a href="../<?php echo $record['_link'] ?>"><?php echo $articlesRecord['_link'] ?></a><br/>



<hr/>
<?php if (!$articlesRecord): ?>
No record found!<br/><br/>
<?php endif ?>
<!-- /STEP2: Display Records -->

<a href="<?php echo $articlesMetaData['_listPage']; ?>">&lt;&lt; Back to list page</a>
-
<a href="mailto:?subject=<?php echo thisPageUrl() ?>">Email this Page</a>






<font face="Arial" size="2">


</td>
</tr>
</table>
<table border="0" cellpadding="5" cellspacing="0" width="1000" id="table4">
<tr>
<td bgcolor="#666666">&nbsp;</td>
</tr>
<tr>
<td bgcolor="#CCCCCC">&nbsp;</td>
</tr>
</table>

</body>

</html>
Sven Sanchez

www.deguate.com

By Jason - July 21, 2010

Hi,

Try changing the code to this (I've highlighted the changes in red):

<?php if($category['_isSelectedBranch'] || $category['_isSelected']){echo "<b>"; $selectedCat=$category['num'];} ?> <a href="articulos.php?category=<?php echo $category['num']?>"><?php echo $category['name']; ?></a> <?php if($category['_isSelectedBranch'] || $category['_isSelected']){echo "</b>";} ?>

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] Sub-categories Tutorial

By svsanchez - July 22, 2010

Hi Jason, I tried your code but it didn't work, subcategories still don't appear in Bold. Here's what I wrote:

<?php $selectedCat=""; ?> <?php foreach($categoryRecords as $category):?> <?php if(!$category['_hasParent']):?> <?php if($category['_isSelectedBranch']|| $category['_isSelected']){echo "<b>"; $selectedCat=$category['num'];} ?> <a href="articulos.php?category=<?php echo $category['num']?>"><?php echo $category['name']; ?></a> <?php if($category['_isSelectedBranch']|| $category['_isSelected']){echo "</b>";} ?> <?php endif ?>
Sven Sanchez

www.deguate.com

By Jason - July 22, 2010

Hi,

Try this:

<?php $selectedCat=""; ?> <?php foreach($categoryRecords as $category):?> <?php if(!$category['_hasParent']):?> <?php if($category['_isSelectedBranch']|| @$_REQUEST['category']==$category['num']){echo "<b>"; $selectedCat=$category['num'];} ?> <a href="articulos.php?category=<?php echo $category['num']?>"><?php echo $category['name']; ?></a> <?php if($category['_isSelectedBranch']|| @$_REQUEST['category']==$category['num']){echo "</b>";} ?> <?php endif ?>
---------------------------------------------------
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] Sub-categories Tutorial

By svsanchez - July 22, 2010

Hi Jason, this code didn't work either, you can see it in www.casahermes.com/articulos.php choose from the categories menu to the left "TECHOS" and you will be presented with 3 subsections on the second column, chose the first one "FIBROCEMENTO" and it will be displayed BUT "FIBROCEMENTOS" will not be in Bold...
Sven Sanchez

www.deguate.com

By Jason - July 23, 2010

Hi,

If you could email CMS login and FTP details to jason@interactivetools.com I can take a closer look.

Please only email this information, don't post it to the forum.

Thanks.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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

By Jason - July 23, 2010

Hi,

I think we have it fixed. The code we were looking at previously was just to output the parent categories, not the sub categories. I changed the code that outputted the sub categories to this:

<?php if($selectedCat): ?>
<?php foreach($categoryRecords as $category): ?>

<?php if ($selectedCat==$category['parentNum']):?>
<?php if($category['_isSelected']){echo "<b>";}?>
<!--<?php echo $category['_listItemStart']; ?>--> <a href="?category=<?php echo $category['num']?>">
<?php echo $category['name']; ?> </a> <!--<?php echo $category['_listItemEnd']; ?>-->
<?php if($category['_isSelected']){echo "</b>";}?>
<?php endif ?> <p>
<?php endforeach ?>
<?php endif ?>


There was also a missing ":" on line 121 that I added in for you.

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] Sub-categories Tutorial

By svsanchez - July 23, 2010

Thank you Jason, that did it... now the only problem is the details page isn't showing the selected subcategory in bold:

http://www.casahermes.com/articulos-details.php?Ej-techos-fibrocemento-1
Sven Sanchez

www.deguate.com