list categories

10 posts by 3 authors in: Forums > CMS Builder
Last Post: February 8, 2010   (RSS)

By jjem - January 27, 2010

Hi,

I would like sort records the list view like following:

Category 1
Sub Category 1
Product 1
Product 2
Product 3
Sub Category 2
Product 1
Product 2
Product 3

Category 2
Sub category 1
Product 4
Product 5
Product 6

I did start to do it manually like this

<!-- Solo Records -->
<h2>Solo recording</h2>
<?php list($discographyRecords, $discographyMetaData) = getRecords(array(
'tableName' => 'discography',
'where' => 'solo_orchestral = "solo"',
)); ?>
<?php foreach ($discographyRecords as $discographyRecords): ?>
<?php echo $discographyRecords['orchestra'] ?><br/>
<?php echo $discographyRecords['conductor'] ?><br/>
<?php echo $discographyRecords['title'] ?><br/> etc

then

<!-- Orchestra Records -->
<h2>Orchestral Recordings</h2>
<?php list($discographyRecords, $discographyMetaData) = getRecords(array(
'tableName' => 'discography',
'where' => 'solo_orchestral = "orchestra"',
)); ?>
<?php foreach ($discographyRecords as $discographyRecords): ?>
<?php //echo $discographyRecords['orchestra'] ?><br/>
<?php echo $discographyRecords['conductor'] ?><br/>
<?php echo $discographyRecords['title'] ?><br/>


I cannot find anything on this forum where I could start to dynamically set this up. Any hint would be great... Thanks for your help

Re: [jjem] list categories

Hi,

Have you looked this over? It might get you pointed in the right direction.

http://www.interactivetools.com/iforum/Products_C2/CMS_Builder_F35/Sub-categories_Tutorial_P77230/

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] list categories

By jjem - January 28, 2010 - edited: January 28, 2010

Thanks Jerry,

It definitely got me closer. The screenshot 1.png is what I get. Screenshot 2.png is what I try to achieve. So it is like a menu tree, but the titles of the articles have to show up directly under the categories or subcategories.

Here is the code I used:
<ul>
<li><a href="?">(All Articles)</a></li>
<?php foreach ($cd_categoriesRecords as $categoryRecord): ?>
<?php echo $categoryRecord['_listItemStart'] ?>
<?php if ($categoryRecord['_isSelected']): ?>
<b>
<?php endif ?>
<a href="?category=<?php echo $categoryRecord['num'] ?>"><?php echo $categoryRecord['name'] ?></a>
<?php if ($categoryRecord['_isSelected']): ?>
</b>
<?php endif ?>
<?php echo $categoryRecord['_listItemEnd'] ?>
<?php endforeach ?>
</ul>
<!-- content -->
<?php foreach ($discographyRecords as $record): ?>
<?php echo $record['title'] ?><br/>
<?php endforeach ?>
<?php if (!$discographyRecords): ?>
No records were found!<br/>
<br/>
<?php endif ?>
<!-- end content -->

Wondering if I could integrate the content part into the menu. I actually do not need it as a menu, it is more a tree in list view. Any hint would be great. Thanks
Attachments:

1_001.png 62K

2.png 98K

Re: [jjem] list categories

By Chris - January 29, 2010 - edited: January 29, 2010

Hi jjem,

I think the simplest way to do this would be to load all discography records at the top of the page:

<?php
list($discographyRecords, $discographyMetaData) = getRecords(array(
'tableName' => 'discography',
));
?>


...then loop over your discography records after displaying each (sub)category and skip over the ones that don't match the category: (new code in red)

<?php foreach ($cd_categoriesRecords as $categoryRecord): ?>
<?php echo $categoryRecord['_listItemStart'] ?>
<?php if ($categoryRecord['_isSelected']): ?> <b> <?php endif ?>
<a href="?category=<?php echo $categoryRecord['num'] ?>"><?php echo $categoryRecord['name'] ?></a>
<?php if ($categoryRecord['_isSelected']): ?> </b> <?php endif ?>

<?php foreach ($discographyRecords as $discographyRecord): ?>
<?php if ($discographyRecord['category'] != $categoryRecord['num']) { continue; } // skip records which aren't in this category ?>
<a href="<?php echo $discographyRecord['_link'] ?>"><?php echo $discographyRecord['title'] ?></a>
<?php endforeach ?>

<?php echo $categoryRecord['_listItemEnd'] ?>
<?php endforeach ?>


You may need to change the names of the fields above (i.e. 'category', 'title') if I haven't guessed at your configuration correctly.

I hope this helps! Please let me know if you have any questions.
All the best,
Chris

Re: [chris] list categories

By jjem - February 3, 2010

Hi Chris,

Thanks for the hint. here is the full page code. I still get only the (sub)categories listed as wanted but the content (<?php echo $discographyRecord['title'] ?>) doesn't appear... I'd much appreciate another "coup de pouce" (help)...
Result of that page in the attached screenshot


<?php
require_once "/.../.../.../.../html/cmsAdmin/lib/viewer_functions.php";
list($cd_categoriesRecords, $selectedCategory) = getCategories(array(
'tableName' => 'cd_categories',
));

list($discographyRecords, $discographyMetaData) = getRecords(array(
'tableName' => 'discography',
));

?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title> Discography</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link rel="stylesheet" type="text/css" href="css/360player.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script src="http://cdn.jquerytools.org/1.1.2/full/jquery.tools.min.js"></script>
<script type="text/javascript" src="js/berniecode-animator.js"></script>
<script src="js/soundmanager2.js" language='JavaScript' type="text/javascript"></script>
<script src="js/360player.js" language='JavaScript' type="text/javascript"></script>
</head>
<body>
<?php include('includes/header.html'); ?>
<div id="contentWrapper">
<div class="pageTitle">Discography</div>
<!-- InstanceBeginEditable name="pageContent" -->
<div class="pageContent">
<ul>

<?php foreach ($cd_categoriesRecords as $categoryRecord): ?>
<?php echo $categoryRecord['_listItemStart'] ?>
<?php if ($categoryRecord['_isSelected']): ?>
<b>
<?php endif ?>
<?php echo $categoryRecord['name'] ?>
<?php if ($categoryRecord['_isSelected']): ?>
</b>
<?php endif ?>

<?php foreach ($discographyRecords as $discographyRecord): ?>
<?php if ($discographyRecord['category'] != $categoryRecord['num']) { continue; } // skip records which aren't in this category ?>
<?php echo $discographyRecord['title'] ?>
<?php endforeach ?>


<?php echo $categoryRecord['_listItemEnd'] ?>
<?php endforeach ?>
</ul>

<?php if (!$discographyRecords): ?>
No records were found!<br/>
<br/>
<?php endif ?>
</div>
</div>
</body>
</html>

Attachments:

3_001.png 45K

Re: [chris] list categories

By jjem - February 5, 2010

Hi Chris,

See attachement....

Re: [jjem] list categories

By Chris - February 5, 2010

Hi jjem,

A ha! Your category list fields are multi-value. I should have asked!

Does this change solve the problem?

<?php foreach ($discographyRecords as $discographyRecord): ?>
<?php if (strpos($discographyRecord['category'], "\t".$categoryRecord['num']."\t") === false) { continue; } // skip records which aren't in this category (multi-value) ?>
<a href="<?php echo $discographyRecord['_link'] ?>"><?php echo $discographyRecord['title'] ?></a>
<?php endforeach ?>


Please let me know if you have any questions.
All the best,
Chris

Re: [chris] list categories

By jjem - February 5, 2010

Chris thanks for the quick reply. I tested you solution which is going to to corrrect way. the isseu now is that the items are listed under each category and subcategory.

So I have all CD's listed under to top category. Then part of them are listed under the first sub-category again. Then they are listed again in the second subcategory.... see new attachement.

Sorry for the trouble...

Re: [jjem] list categories

By Chris - February 8, 2010

Hi jjem,

I think the simple solution is to change your items so they only belong to subcategories, not parent categories. Is there a reason why you need your items to be assigned to parent categories as well? Maybe it would be simpler to address the other issue.
All the best,
Chris