Sections, categories and subcategories

9 posts by 4 authors in: Forums > CMS Builder
Last Post: January 26, 2010   (RSS)

By (Deleted User) - December 29, 2009

We have a website with different sections (information, products, resources, etc). Each SECTION is compounded by CATEGORIES and some CATEGORIES have SUBCATEGORIES.

How can we show at the List page (Section Home Page), only the CATEGORY? and then, when somebody clicks on the category link is linked to another list type page showing the SUBCATEGORIES? We are setting the Category as the Top Level Category and subcategories are being assigned to each category.

Today, despite of assigning to the Categories as "none, top level category" at the time of listing the content, we see everything, categories and subcategories.

is there a way to write a mySQL statement where parentCategory = none? for instance? Which is the value that we need to put to replace "none"? (or "not none" in case of showing the subcategory home page)?

Thank you,

Re: [rneube] Sections, categories and subcategories

By Chris - January 4, 2010

Hi rneube,

You can accomplish these requirements with getCategories(). Here is a list of the potential options you can use:

list($categoryRecords, $selectedCategory) = getCategories(array(
'tableName' => 'category', // REQUIRED
'rootCategoryNum' => '0', // Only categories _below_ this one will be shown (defaults to 0 for all)
'defaultCategory' => 'first', // Enter 'first', a category number, or leave blank '' for none
'ulAttributes' => " class='muList' ", // add html attributes to <ul> tags
'selectedCategoryNum' => '', // defaults to getNumberFromEndOfUrl()
'categoryFormat' => 'showall', // showall, onelevel, twolevel, breadcrumb
));


To list only the categories and not the subcategories, you'll want to set 'categoryFormat' => 'onelevel', 'rootCategoryNum' => '0'. When someone clicks on a category link, you'll want to use 'categoryFormat' => 'onelevel', 'rootCategoryNum' => $categoryNum -- where $categoryNum is the record number of the category clicked on.

Please post the full PHP source code for the page you're working on and I can help get it working how you'd like.

I hope this helps. If you have any questions, please let me know.
All the best,
Chris

Re: [rneube] Sections, categories and subcategories

By (Deleted User) - January 5, 2010

Thank you for such a detailed explanation. Anyway, I think it is too much for me, because of my lack of programming knowledge. I would wish to have more documentation about what your excellent application can do and how to do it.

The full code of the page is here:

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

require_once "/home/activefilings/public_html/cmsAdmin/lib/viewer_functions.php";

list($servicesRecords, $servicesMetaData) = getRecords(array(
'tableName' => 'services',
'perPage' => '10',
'loadUploads' => '0',
'allowSearch' => '0',
));

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<style type="text/css">
body { font-family: arial; }
.instructions { border: 3px solid #000; background-color: #EEE; padding: 10px; text-align: left; margin: 25px}
</style>
</head>
<body>

<!-- INSTRUCTIONS -->
<div class="instructions">
<b>Sample List Viewer - Instructions:</b>
<ol>
<?php ?>
<li><b>Remove any fields you don't want displayed.</b> (Most list pages only have title and link fields.)</li>
<li>Rearrange remaining fields to suit your needs.</li>
<li>Copy and paste code into previously designed page (or add design to this page).</li>
</ol>
</div>
<!-- /INSTRUCTIONS -->

<!-- STEP2: Display Records (Paste this where you want your records to be listed) -->
<h1>Services - List Page Viewer</h1>
<?php foreach ($servicesRecords as $record): ?>
Record Number: <?php echo $record['num'] ?><br/>
Parent Category: <?php echo $record['parentNum'] ?><br/>
Name: <?php echo $record['name'] ?><br/>
Content: <?php echo $record['content'] ?><br/>
Headline: <?php echo $record['headline'] ?><br/>
Keywords: <?php echo $record['keywords'] ?><br/>
Description: <?php echo $record['description'] ?><br/>
Order Here: <?php echo $record['order_here'] ?><br/>
Add: <?php echo $record['add'] ?><br/>
_link : <a href="<?php echo $record['_link'] ?>"><?php echo $record['_link'] ?></a><br/>
<hr/>
<?php endforeach ?>

<?php if ($servicesMetaData['invalidPageNum']): ?>
Results page '<?php echo $servicesMetaData['page']?>' not found, <a href="<?php echo $servicesMetaData['firstPageLink'] ?>">start over &gt;&gt;</a>.<br/><br/>
<?php elseif (!$servicesRecords): ?>
No records were found!<br/><br/>
<?php endif ?>
<!-- /STEP2: Display Records -->


<!-- STEP3: Display Page Links (Paste anywhere below "Load Record List") -->
<?php if ($servicesMetaData['prevPage']): ?>
<a href="<?php echo $servicesMetaData['prevPageLink'] ?>">&lt;&lt; prev</a>
<?php else: ?>
&lt;&lt; prev
<?php endif ?>

- page <?php echo $servicesMetaData['page'] ?> of <?php echo $servicesMetaData['totalPages'] ?> -

<?php if ($servicesMetaData['nextPage']): ?>
<a href="<?php echo $servicesMetaData['nextPageLink'] ?>">next &gt;&gt;</a>
<?php else: ?>
next &gt;&gt;
<?php endif ?>
<!-- /STEP3: Display Page Links -->


</body>
</html>




This is the page we named Index.php and it should show only the main categories (services). This code shows everything, categories, and each service. I don't know where to put the code you wrote.

Thank you!

Re: [rneube] Sections, categories and subcategories

By Chris - January 5, 2010

Hi rneube,

Does this code do what you want?

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

require_once "/home/activefilings/public_html/cmsAdmin/lib/viewer_functions.php";

list($servicesRecords,) = getCategories(array(
'tableName' => 'services',
'loadUploads' => '0',
'selectedCategoryNum' => '', // defaults to getNumberFromEndOfUrl()
'categoryFormat' => 'onelevel',
));

?>

<!-- STEP2: Display Records (Paste this where you want your records to be listed) -->
<h1>Services - List Page Viewer</h1>
<?php foreach ($servicesRecords as $categoryRecord): ?>
<?php echo str_repeat("&nbsp; &nbsp; &nbsp;", $categoryRecord['depth']); ?>
<?php if ($categoryRecord['_isSelected']): ?><b><?php endif; ?>
<a href="?<?php echo $categoryRecord['num'] ?>"><?php echo $categoryRecord['name'] ?></a><br/>
<?php if ($categoryRecord['_isSelected']): ?></b><?php endif; ?>
<?php endforeach ?>
<!-- /STEP2: Display Records -->

All the best,
Chris

Re: [chris] Sections, categories and subcategories

By (Deleted User) - January 5, 2010

Hi Chris,

Thank you very much. It is very close to what I was looking for.

I would like to show the Name (title) and a litle abstract (headline). When somebody clicks on the title, instead of showing the subcategories at the same page, I would like to open a new page where the subcategories are showed in the same way (title, headline). Finally, if they click there, they could be showed the service page.

See what we have now, after having implemented your code:

http://www.activefilings.com/en/services/index.php

If you click on -for instance- Business Formation Services (1st choice), you expand the different services included in that category (basic inc service, full inc service, and so on). This list should be showed in a new page. The new page would link the service's name to the service page (which it cannot be displayed now).

Is that possible? Are we doing the right thing?

Thank you.

Re: [rneube] Sections, categories and subcategories

By (Deleted User) - January 6, 2010

We managed to correct the code and get a decent layout. Now, you can click on the individual items and you are linked to the service description page.

Thank you for your help!

Re: [rneube] Sections, categories and subcategories

By gkornbluth - January 26, 2010

Hi Meube,

Could you share some of the details about how you finally ahieved your goal?

Best,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Sections, categories and subcategories

By (Deleted User) - January 26, 2010

We decided to hire the guys at InterativeTools and they did a great (and very affordable) job. I'm sorry but I wouldn't know what to share here. It was not only programming but also a good knowledge of the platform.