Just not understanding how to set up Category menus
44 posts by 5 authors in: Forums > CMS Builder
Last Post: September 22, 2009 (RSS)
By Codee - August 12, 2009
http://www.interactivetools.com/iforum/Products_C2/CMS_Builder_F35/gforum.cgi?post=71850;search_string=category%20menu;t=search_engine#71850
and
Dave's original from last year at
http://www.interactivetools.com/forum/gforum.cgi?post=64259#64259
To be honest, I am lost on this. I've been trying to set up a test for doing the multilevel category thing and just am not "seeing" how to do it but I know what I want...it's simple:
I want to list the Manufacturers (category list) and when each manufacturer is chosen, I want it to list that manufacturers' models. Quick example:
Cheverolet
- Malibu
- AstroVan
- Citation
Chrysler
- Conquest
- Sebring
- Town and Country
Dodge
- Caravan
- Avenger
- Truck
If I could get a 1-2-3, a-b-c start for doing this I could probably fly on my own. The previously mentioned forum posts lost me.
Re: [equinox69] Just not understanding how to set up Category menus
By Chris - August 12, 2009
Firstly, you'll want two sections in CMS Builder: Manufacturers (which should be a Category Menu) and Models (which should be Multi Record). Next, you'll need to modify your Models section to add a field.
Field Label: Manufacturer
Field Name: manufacturer
Field Type: list
Field Options:
Display As: pulldown
List Options: Get options from database (advanced)
Section Tablename: manufacturers
Use this field for option values: num
Use this field for option labels: name
Input Validation:
Required (checked) user may not leave field blank
Now create some example Manufacturers and Models. You'll want at least two of each to be able to test everything properly, with one of your manufacturers having a Parent Category of another manufacturer.
Next, let's build a list page Viewer for your Models. Leave all the options defaulted and copy and paste the code into a new file called modelsList.php. If you look at that page in a web browser, it should list all your models, regardless of manufacturer. However, if you browse to modelList.php?manufacturer=1, you'll only see models assigned to the first manufacturer you created.
Finally, let's build a list page Viewer for your Manufacturers. Once again, leave all the options defaulted and paste the code into a new file called manufacturersList.php. If you look at that page in a web browser, it should list all your manufacturers. We need to make some changes to manufacturersList.php. Change the following line in STEP 1 (near the top):
list($manufacturersRecords, $manufacturersMetaData) = getRecords(array(
to this:
list($manufacturersRecords, $manufacturersMetaData) = getCategories(array(
and also replace all of STEP 2 with the following:
<!-- STEP2: Display Records (Paste this where you want your records to be listed) -->
<h1>Manufacturers - List Page Viewer</h1>
<ul>
<?php foreach ($manufacturersRecords as $record): ?>
<?php echo $record['_listItemStart'] ?>
<a href="modelList.php?manufacturer=<?php echo $record['num'] ?>"><?php echo $record['name'] ?></a>
<?php echo $record['_listItemEnd'] ?>
<?php endforeach; ?>
<?php if (!$manufacturersRecords): ?>
<li>No records were found!</li>
<?php endif ?>
</ul>
<!-- /STEP2: Display Records -->
Now, when you browse to manufacturersList.php, you'll see an indented list of your manufacturers, and clicking on one should bring you to modelList.php, listing the models you've assigned to that manufacturer.
Please let us know if that gets you up and running, if you run into any trouble along the way, or if you have any questions. :D
Chris
Re: [chris] Just not understanding how to set up Category menus
By Codee - August 12, 2009
THANK YOU for the simple 1-2-3! I will give it a go and report back.
Cheers!
Re: [equinox69] Just not understanding how to set up Category menus
By sublmnl - August 26, 2009 - edited: August 26, 2009
Did you get this to work?
Our client wanted a page that lists all projects
(not a list as we know it in code...)
Now they want Public and Private.
So my idea is to have a Navigation link to a 'list' 'page where they select Public or Private then see the (public or private) Project titles and a small icon and description next to it. Never both at the same time.
I think the above is the way to do it.
Although I do not need a click through to a detail page.
Just a list page for all items. (I could leave the link out of the php code and it wouldn't matter anyhow)
I was thinking this could be the answer....
?
(Edited)
One other thought I had is to use one page and pull in two records in a single page (can we do that?), but I want the client to be able to drag/sort them in the CMS, so I'm guessing we'd have to use a multirecord of some kind.
hopefully someone offer some advice.
Re: [sublmnl] Just not understanding how to set up Category menus
By Chris - August 27, 2009
If you're categorizing records into only two categories (Public and Private), and you don't expect to add more categories, it may be simpler to use a single Multi record section.
For example, I created a Multi record section called Projects and added a field called "access" of type "list", and entered these List Options:
Public
Private
Then I created some sample records, some Public, some Private. I generated list page viewer code, which listed all of my projects. I changed the code in STEP 1 to collect two lists of projects -- one for Public projects, one for Private projects:
list($publicProjectsRecords, $projectsMetaData) = getRecords(array(
'tableName' => 'projects',
'where' => 'access = "Public"'
));
list($privateProjectsRecords, $projectsMetaData) = getRecords(array(
'tableName' => 'projects',
'where' => 'access = "Private"'
));
I've attached the complete PHP list page for reference.
I hope this helps! Please let us know if you have any questions or comments.
P.S. Yes, you can load as many records (or record sets) into one page as you want.
Chris
Re: [chris] Just not understanding how to set up Category menus
By sublmnl - August 30, 2009 - edited: August 30, 2009
I just got a chance to get back on this and I have an error:
MySQL Error: Unknown column 'access' in 'where clause'
I checked for case issues.
I am no php guru by any means. I'd say I'm somewhere in between a beginner and novice. I do appreciate your help also sorry to hijack the original thread but I think you are on to what we need.
Anyhow...
attached is the relevant portion of the code and the original generated code.
I create the field access list and changed the two options to public and private. Not sure whats up now.
Something else good may come of this too, you showed me the list 'thing' and now I have some other ideas for future clients. :)
Re: [sublmnl] Just not understanding how to set up Category menus
By Chris - August 30, 2009
I took a look at your code and noticed the following:
acccess: <?php echo $record['acccess'] ?>
It seems that your field is called "acccess" and mine is called "access". You'll either need to rename your field or change the where clauses to reflect your spelling.
Hope this helps! Please let us know if you have any more questions or comments.
Chris
Re: [chris] Just not understanding how to set up Category menus
By sublmnl - August 31, 2009 - edited: August 31, 2009
dang.
Must've been tired.
That did the trick.
I edited the cms and updated the spelling error in the php code.
Thanks Chris.
Now what if we had one more option?
Like expired or active?
Can we do the same thing and have two 'access' points to separate the lists into two more sections?
Re: [sublmnl] Just not understanding how to set up Category menus
By Chris - August 31, 2009
list($publicActiveProjectsRecords, $projectsMetaData) = getRecords(array(
'tableName' => 'projects',
'where' => ' access = "Public" AND status = "Active" '
));
list($privateActiveProjectsRecords, $projectsMetaData) = getRecords(array(
'tableName' => 'projects',
'where' => ' access = "Private" AND status = "Active" '
));
list($publicExpiredProjectsRecords, $projectsMetaData) = getRecords(array(
'tableName' => 'projects',
'where' => ' access = "Public" AND status = "Expired" '
));
list($privateExpiredProjectsRecords, $projectsMetaData) = getRecords(array(
'tableName' => 'projects',
'where' => ' access = "Private" AND status = "Expired" '
));
(Advanced note: if you follow this approach much further and wind up with more than 10 getRecords() calls (and are having problems with page loading speed) it's possible to do the filtering in PHP -- but you'd lose simplicity and flexibility, so that should be a last resort.)
Hope this helps! Please let us know if you have any questions or comments.
Chris
Re: [chris] Just not understanding how to set up Category menus
By sublmnl - August 31, 2009 - edited: August 31, 2009
Works - now I need to format it and add some uploads.
Here is my code to share with the class:
(Keep in mind I did not want to use a detail page but you certainly can and add link and on the detail page have a summary section there to get full info... )
Head code:
list($publiccurrentprojectsRecords, $projectsMetaData) = getRecords(array(
'tableName' => 'all_projects',
'where' => 'access = "public" AND status = "current" '
));
list($publiccompletedprojectsRecords, $projectsMetaData) = getRecords(array(
'tableName' => 'all_projects',
'where' => 'access = "public" AND status = "completed" '
));
list($privatecurrentprojectsRecords, $projectsMetaData) = getRecords(array(
'tableName' => 'all_projects',
'where' => 'access = "private" AND status = "current" '
));
list($privatecompletedprojectsRecords, $projectsMetaData) = getRecords(array(
'tableName' => 'all_projects',
'where' => 'access = "private" AND status = "completed" '
));
body somewhere.... ;)
<p><strong>Current Public Jobs:</strong></p>
<?php foreach ($publiccurrentprojectsRecords as $record): ?>
<h4><?php echo $record['title'] ?></h4>
<p><?php echo $record['content'] ?></p>
<?php endforeach; ?>
<?php if (!$publiccurrentprojectsRecords): ?>
No current public projects were found!<br/><br/>
<?php endif ?>
<!-- next record -->
<p><strong>Completed Public Jobs:</strong></p>
<?php foreach ($publiccompletedprojectsRecords as $record): ?>
<h4><?php echo $record['title'] ?></h4>
<p><?php echo $record['content'] ?></p>
<hr/>
<?php endforeach; ?>
<?php if (!$publiccompletedprojectsRecords): ?>
No current public projects were found!<br/><br/>
<?php endif ?>
<!-- next record -->
<p><strong>Current Private Jobs:</strong></p>
<?php foreach ($privatecurrentprojectsRecords as $record): ?>
<h4><?php echo $record['title'] ?></h4>
<p><?php echo $record['content'] ?></p>
<?php endforeach; ?>
<?php if (!$privatecurrentprojectsRecords): ?>
No current private projects were found!<br/><br/>
<?php endif ?>
<!-- next record -->
<p><strong>Completed Private Jobs:</strong></p>
<?php foreach ($privatecompletedprojectsRecords as $record): ?>
<h4><?php echo $record['title'] ?></h4>
<p><?php echo $record['content'] ?></p>
<?php endforeach; ?>
<?php if (!$privatecompletedprojectsRecords): ?>
No current private projects were found!<br/><br/>
<?php endif ?>