Categories and records grouped on same page
17 posts by 4 authors in: Forums > CMS Builder
Last Post: May 13, 2009 (RSS)
<?php if ($record['category'] != @$lastCategory): ?>
<?php $lastCategory = $record['category']; ?>
<h1><?php echo $record['category'] ?></h2>
<?php endif ?>
But the problem I am having is that, on the viewer page, the categories are being grouped together whenever a record has more than one category assigned to it. I want to be able to show each category separately and multiple instances of a record if it exists in various categories.
Re: [sparks] Categories and records grouped on same page
By Dave - February 25, 2009
That ones a little tricky and requires a bit of custom code. Can you attach your section schema file (found in cmsAdmin/data/schema/yourSection.ini.php) and your viewer file? (Attach them to the post, don't copy and paste their contents into the message).
I'll see if I can write up something that will work for you.
Hope that helps!
interactivetools.com
Re: [Dave] Categories and records grouped on same page
Re: [sparks] Categories and records grouped on same page
By ross - February 26, 2009
I have some code for you to try out. It's actually a little more advanced than what we normally post but it is copy and pasteable so you should be ok. Here's the code:
<?php
$html = "";
// loop over categories
$categoryOptions = getListOptions('meet_our_advertisers', 'category'); // tablename, fieldname
foreach (array_keys($categoryOptions) as $categoryName) {
$heading = "<br><br><strong>$categoryName</strong><br>";
// loop over records
$rows = "";
foreach ($meet_our_advertisersRecords as $record) {
$isRecordInCategory = strpos($record['category'], "\t$categoryName\t") !== false;
if ($isRecordInCategory){ $rows .= $record['title'] . "<br/>";}
}
// add to html
if ($rows) {
$html .= $heading . $rows;
}
}
//
print $html;
?>
Just paste that where you want the list of categories and articles to appear. It's setup to only display a category name if there is actually an article in it.
Let me know how you make out :).
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com
Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/
Re: [ross] Categories and records grouped on same page
Re: [sparks] Categories and records grouped on same page
By ross - March 2, 2009
To get the articles linking, you would need to change this line of code:
if ($isRecordInCategory){ $rows .= $record['title'] . "<br/>";}
Try replacing that with this:
if ($isRecordInCategory){ $rows .= "<a href='" . $record['_link'] . "'>$record['title'] . "</a><br/>";}
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com
Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/
Re: [ross] Categories and records grouped on same page
By 28sparks - March 3, 2009
The code did not work. The page no longer loads. Any ideas?
Thanks.
Re: [sparks] Categories and records grouped on same page
By Dave - March 4, 2009
Try this instead:
if ($isRecordInCategory){ $rows .= "<a href='{$record['_link']}'>{$record['title']}</a><br/>"; }
interactivetools.com
Re: [Dave] Categories and records grouped on same page
By 28sparks - March 4, 2009
Re: [ross] Categories and records grouped on same page
By petejdg - May 4, 2009 - edited: May 4, 2009
I am trying to do almost the same thing. I created a category with two staff sections, then records under each staff section. I would like to show the first category section with the records and then the next category with records. I tried to use the code you provided and tweak to make it work for me but I cannot get anything to show. I thought maybe I could make it work for me....
can you look at see what i need to make it work?
(I guess my list is just a dropdown and wouldn't have to check against multiple categories....)
Thanks,
pete