Main
Index
Search
Posts
Who's
Online
Log
In

Home: Products: CMS Builder:
Multi-level Category Functions

 

First page Previous page 1 2 3 Next page Last page  View All


Dave
Staff / Moderator


Jul 31, 2008, 4:34 PM

Post #1 of 63 (34200 views)
Shortcut
Multi-level Category Functions Can't Post

Hello all,

We have some new viewer functions to display multi-level categories. These will be in the next release but I'll show you how to use them now. Note that we haven't added them to the code generator (that's next) so for now it's still an advanced feature. That said, here's how it works.

The functions let you display a multi-level category menu as an indented tree or as a <ul> list (which can work with drop down menu systems). You can also specify a couple formats to display the menu and then "drill down" where clicking on an option shows the "sub options".

Note that currently categories to pages are one to one. Meaning each category maps to one page, not a list of records from another section. There's things you can do to make that work but for this post I'll just be explaining the basics.

Note that I've attached two files: viewer_functions.php and categoryList.php (a sample category list viewer).

Here's how to use this.

1) Make sure you're running v1.20 or newer (upgrade if needed)

2) Create a new "Category" section.

3) Add some record to the category section - some under others.

4) Under Admin > Section Editors > Your Category Section > Viewer Urls - set them both to categoryList.php

5) Either use the attached file (updating the viewer_functions.php path and table name to match your own) or add the following code:


Code
<?php 
/* STEP 1: LOAD RECORDS - Copy this PHP code block to the TOP of your page BEFORE anything else. */
require_once "C:/wamp/www/sb/core2/admin/lib/viewer_functions.php";

list($categoryRecords, $selectedCategory) = getCategories(array(
'tableName' => 'category',
//'selectedCategoryNum' => '', // defaults to getNumberFromEndOfUrl()
'categoryFormat' => 'showall', // showall, onelevel, twolevel
));

?>


Then use this code to display an html menu:


Code
<!-- category menu --> 
<h3>Nested Menu</h3>
<?php foreach ($categoryRecords as $categoryRecord): ?>

<?php echo str_repeat("&nbsp; &nbsp; &nbsp;", $categoryRecord['depth']); ?>

<?php if ($categoryRecord['_isSelected']): ?><b><?php endif; ?>
<a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a>
<?php if ($categoryRecord['_isSelected']): ?></b><?php endif; ?>
<br/>
<?php endforeach; ?>
<!-- /category menu -->


OR - use this code to display the menu in <ul> format:


Code
  <!-- unordered list --> 
<ul>
<?php foreach ($categoryRecords as $categoryRecord): ?>
<?php echo $categoryRecord['_listItemStart'] ?>

<?php if ($categoryRecord['_isSelected']): ?>
<b><a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a></b>
<?php else: ?>
<a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a>
<?php endif; ?>

<?php echo $categoryRecord['_listItemEnd'] ?>
<?php endforeach; ?>
</ul>
<!-- /unordered list -->


And then use this code to display the selected category:


Code
<?php if (!$selectedCategory): ?> 
No record selected
<?php endif; ?>

<?php if ($selectedCategory): ?>

<h3><?php echo $selectedCategory['name'] ?></h3>
<?php echo $selectedCategory['content'] ?>

<?php endif; ?>


This is a pretty powerful new feature and makes it very easy to manage web sites where the pages are organized in a hierarchical format.

Give it a try and let me know if you have any questions.

UPDATE: Re-uploaded viewer_functions.php with fixes for issues that Djulia found below.

UPDATE 2: Updated instructions since this code is now included in the latest version.

Dave Edis - Senior Developer
interactivetools.com
 

(This post was edited by Dave on Nov 15, 2010, 9:49 AM)
Attachments: categoryList.php (2.26 KB)


Michael Blake
User

Aug 1, 2008, 1:09 AM

Post #2 of 63 (34188 views)
Shortcut
Re: [Dave] Multi-level Category Functions [In reply to] Can't Post

Hi Dave,
This sounds brilliant and is probably what I am looking for. Are you able to provide a couple of images of the actual page with the new menu? I haven't yet got my CMSB anywhere near production but am keen to know if this will work for my sites.

Mickey


Djulia
User

Aug 1, 2008, 3:59 AM

Post #3 of 63 (34181 views)
Shortcut
Re: [Dave] Multi-level Category Functions [In reply to] Can't Post

Hi Dave,

1) I have an error message with showall :

Strict Standards: Only variables should be assigned by reference in /../lib/viewer_functions.php on line 463
Strict Standards: Only variables should be assigned by reference in /../lib/viewer_functions.php on line 464


2) I also have an error message with the use of the SeoUrls option :

Category Viewer (category) errors
Unknown option 'useSeoUrls' specified
Valid option names are: (...)



You have an idea ?

Thank you for your assistance.

Djulia


P.S.: for Mickey (image-level.gif)


(This post was edited by Djulia on Aug 1, 2008, 5:01 AM)
Attachments: image-level.gif (1.98 KB)
  image-level-selected.gif (2.48 KB)


Michael Blake
User

Aug 1, 2008, 5:07 AM

Post #4 of 63 (34163 views)
Shortcut
Re: [Djulia] Multi-level Category Functions [In reply to] Can't Post

Thanks Djulia,
Hopefully Dave can sort your problem out soon.

Mickey


Dave
Staff / Moderator


Aug 1, 2008, 7:24 AM

Post #5 of 63 (34144 views)
Shortcut
Re: [Djulia] Multi-level Category Functions [In reply to] Can't Post

Hi Djulia,

Can you attach the viewer file you're using?

And what version of PHP are you using?

Thanks!

Dave Edis - Senior Developer
interactivetools.com
 


Djulia
User

Aug 1, 2008, 7:48 AM

Post #6 of 63 (34137 views)
Shortcut
Re: [Dave] Multi-level Category Functions [In reply to] Can't Post

I use the file which you propose : categoryList.php.

My version php is: PHP Version 5.2.6

You have an idea ?

Thanks,

Djulia


P.s.: I made a test with version 6 of PHP, but I have an error message (I use the file htaccess by default) :

Fatal error: Call to undefined function get_magic_quotes_gpc() in /../lib/init.php on line 72



(This post was edited by Djulia on Aug 1, 2008, 8:12 AM)
Attachments: categoryList.php (2.31 KB)


Dave
Staff / Moderator


Aug 1, 2008, 10:42 AM

Post #7 of 63 (34045 views)
Shortcut
Re: [Djulia] Multi-level Category Functions [In reply to] Can't Post

Hi Djulia,

Thanks for that. I've fixed all the issues you mentioned and updated the viewer_functions.php file in the first post. Try that one and it should work better.

Also for PHP 6, it's still in development so we're not supporting it yet. But when it gets closer to release they'll have a list of functions they've removed and changed and we'll go through and write work arounds to support PHP 4/5/6... :) It will be interesting to see how long PHP 4 sticks around for...

Hope that helps!

Dave Edis - Senior Developer
interactivetools.com
 


Djulia
User

Aug 1, 2008, 12:34 PM

Post #8 of 63 (34012 views)
Shortcut
Re: [Dave] Multi-level Category Functions [In reply to] Can't Post

Thank you Dave,
The errors are corrected for me. Smile

I have an observation.

My menu is structured as follows :

Level 1
---Level 2
------Level 3

...and I use the SeoUrls option.

The URL for Level 2 and Level 3 turns over me :
categoryList.php/Level-1-Level-2-Level-3/

It will be possible, with the final version, to obtain:
categoryList.php/Level-1/Level-2/Level-3/

I also wonder about the "id" which accompanies the URL.
It will be possible to remove it ?

Thanks for the feedback.

Djulia



Dave
Staff / Moderator


Aug 1, 2008, 1:09 PM

Post #9 of 63 (33998 views)
Shortcut
Re: [Djulia] Multi-level Category Functions [In reply to] Can't Post

Hi Djulia,

You need to use absolute urls when using SEO urls. Try setting the Viewer Urls under "Section editors" to /categoryList.php or whatever the path from your website root is. That should fix the Level-1-Level-2-Level-3 problem.

Next, you can remove id, but it requires custom php code. For simplicity the viewers look for the record number on the end of the url. So if you had a field for 'filename' say you'd need to parse that out of the url, look up the category with the matching filename, and then set it's record number in the 'selectedCategoryNum' option. You need something unique to match again to know which record or category to load or show as selected.

It's basically the same process as removing the 'id' from any of the viewers.

Hope that helps!

Dave Edis - Senior Developer
interactivetools.com
 


Djulia
User

Aug 1, 2008, 1:33 PM

Post #10 of 63 (33993 views)
Shortcut
Re: [Dave] Multi-level Category Functions [In reply to] Can't Post

Thank you Dave,

I already tested your proposal, but that does not function.

Even with option SEO on false, I obtain :

for Level-1
/categoryList.php?Level-1

for Level-2
/categoryList.php?Level-1-Level-2

and for Level-3
/categoryList.php?Level-1-Level-2-Level-3

"/" is automatically replaced by "-".

Another idea ?


Thanks,

Djulia


(This post was edited by Djulia on Aug 1, 2008, 1:36 PM)


Dave
Staff / Moderator


Aug 1, 2008, 1:48 PM

Post #11 of 63 (33984 views)
Shortcut
Re: [Djulia] Multi-level Category Functions [In reply to] Can't Post

Hmm, can you email me CMS and FTP login so I can take a look (to dave@interactietools.com). Let me know if that works for you.

Dave Edis - Senior Developer
interactivetools.com
 


Djulia
User

Aug 1, 2008, 3:07 PM

Post #12 of 63 (33975 views)
Shortcut
Re: [Dave] Multi-level Category Functions [In reply to] Can't Post

My excuses, Dave.

The urls are correct, I believe that I make simply an error of comprehension.

What I obtain:

Level 1 (id =1)
/categoryList.php/Level-1-1/

Level 2 (id =3)
/categoryList.php/Level-1-Level-2-3/

Level 3 (id =2)
/categoryList.php/Level-1-Level-2-Level-3-2/

---

In fact, I sought to obtain :

/categoryList.php/Level-1-1/Level-2-3/
/categoryList.php/Level-1-1/Level-2-3/Level-3-2/



And later with of records :

/categoryList.php/SectionName1-1/SectionName2-3/recordName1-1/

I will await the final version for better understanding the use (...)

Thanks,

Djulia



(This post was edited by Djulia on Aug 2, 2008, 8:10 AM)


Dave
Staff / Moderator


Aug 1, 2008, 3:28 PM

Post #13 of 63 (33965 views)
Shortcut
Re: [Djulia] Multi-level Category Functions [In reply to] Can't Post

Ok I understand.

You can control which field is displayed in the url before the "id" by setting "filename fields" under: Section Editors > Viewer Urls.

The simplest solution might be to just set this to 'name' instead of 'breadcrumb'

But by default it will use 'breadcrumb' and convert non-word characters to "-" so if you have a breadcrumb of: News : Technology : Web. So it becomes: News-Technology-Web

You could create the links in whatever format you like instead of using _link. For example if you created a fieldname called filename you could have:

<a href="/path/to/viewer.php?<?php echo $categoryRecord['filename'] ?>-<?php echo $categoryRecord['num'] ?>">

To link as: viewer.php?filename-here-123

And have it display whatever you want.

Would that work for you?

Dave Edis - Senior Developer
interactivetools.com
 


Djulia
User

Aug 2, 2008, 7:51 AM

Post #14 of 63 (33856 views)
Shortcut
Re: [Dave] Multi-level Category Functions [In reply to] Can't Post

Hi Dave,

That can solve my problem. But, I think that it is preferable to await the use with of records in a section to have an better general view.

On that subject, I tried to bind my section "category" with another section (mySection) in order to obtain a menu :

Admin > Section Editors > Field Editor

mySection :

Field Label == Breadcrumb
Field Type == List
List Options == Get options from database (avanced)
Section Tablename == category
Use this field for option values == breadcrumb
Use this field for option labels == breadcrumb

...in mySectionList.php

<?php foreach ($mySectionRecords as $record):
if ($record['_filename'] == 'Contact' OR $record['_filename'] == 'Home') { continue; }
?>
<li><a href="<?php echo $record['breadcrumb'] ?><?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a></li>
<?php endforeach; ?>

My problem, it is that "breadcrumb" gives for example :
"News: Technology: Web" and not "News-Technology-Web".

I think that the final version will correct this problem ?
Or, your approach will be different ?

Thank you for your answer.

Djulia



(This post was edited by Djulia on Aug 2, 2008, 9:21 AM)


Dave
Staff / Moderator


Aug 4, 2008, 6:27 PM

Post #15 of 63 (33785 views)
Shortcut
Re: [Djulia] Multi-level Category Functions [In reply to] Can't Post

Hi Djulia,

I haven't developed a way to bind two sections together and have articles in a specific category. Right now each category maps to a single page.

To have multiple articles or records in a category and list them we'd need to figure out an url format that would work for that. It would need to have some kind of category ID, and a page number. I haven't decided on a format or written functions for that yet. That was going to be the next step.

I don't know how quickly we can do that or how complex it will be but we can try and figure out some of the details now.

A simple way would be to add the page number on the end, but this will make it hard to determine which is the page number and which is the category number. Also, if we match against "page" it's in english.

category.php?category/childcat-3/page2

Matching category "filenames" such as "News/World" is another method but if any of the category names change then all the old urls will break. That's the benefit of using the number in the url.

How would you like to see it work?

Dave Edis - Senior Developer
interactivetools.com
 


sidcam
User

Aug 7, 2008, 3:52 PM

Post #16 of 63 (33426 views)
Shortcut
Re: [Dave] Multi-level Category Functions [In reply to] Can't Post

Dave-

Will this function like the Parent/Sub-Catergory function in Article Manager then? If so that's the one last major piece of AM that CMS Builder is missing. What's a best guess on when that will be released? Will we be able to take existing categories and reassign them to a parent category (or move them around) in the same fashion as AM?

Thanks, Sid


Dave
Staff / Moderator


Aug 11, 2008, 8:32 PM

Post #17 of 63 (33229 views)
Shortcut
Re: [sidcam] Multi-level Category Functions [In reply to] Can't Post

Hi Sid,

You can currently move categories around like you can in Article Manager. The last part remaining is to have it so you can have multiple articles assigned to a category. Right now each category just represents one page.

This is possible (multiple articles per category) right now with some specific code, we just need to figure out how to make it easy. Eventually we intend to add options to the code generator for all these types of pages or sections that you might want to generate.

There's no ETA on this yet, but it's very high on our list.

Hope that helps!

Dave Edis - Senior Developer
interactivetools.com
 


sidcam
User

Aug 11, 2008, 10:08 PM

Post #18 of 63 (33219 views)
Shortcut
Re: [Dave] Multi-level Category Functions [In reply to] Can't Post

Thanks for the reply. I've been very impressed with the speed the software is evolving.

I'm not exactly sure how I would deploy single record sub-sections. Going to have to give that some thought.

The site I'm working on now has the basic layout of a newspaper site and the main section pages are calling 10+ multiple record tables from the DB. If I understand you right, In the future I'll be able to take an existing table and reassign it to be a sub-section without having to recreate it and manually transfer over the content in the fields, correct?

I was also trying to figure out how I set up one RSS feed for a section when the section is actually 10 seperate tables. This would appear to solve that as well.


Dave
Staff / Moderator


Aug 13, 2008, 6:40 PM

Post #19 of 63 (32943 views)
Shortcut
Re: [sidcam] Multi-level Category Functions [In reply to] Can't Post

The goal is to eventually have it be able to do the same thing as Article Manager. So you could have an Articles menu and a Category menu and manage a large part of the site with just that.

You might be able to do a multi-section RSS feed with the multiSearch feature. You can read more about that here: http://www.interactivetools.com/iforum/gforum.cgi?post=63778

It supports pulling 2 fields, title and summary, from each table. So if that would be enough for the RSS it would work. Otherwise if you need 3+ fields we'd need to custom program it or look at other solutions.

Hope that helps!

Dave Edis - Senior Developer
interactivetools.com
 


chassa2556
User

Dec 9, 2008, 3:13 PM

Post #20 of 63 (29365 views)
Shortcut
Re: [Dave] Multi-level Category Functions [In reply to] Can't Post

Hi Dave
Can a walkthrough of the menu system please be added to the advanced topics tutorials in the CMS Builder documentation. It would be really helpful if this was included with screen grabs. The advanced topics section is promising but it only seems to remain looking slightly like a work in progress.


aev
User

Dec 9, 2008, 10:26 PM

Post #21 of 63 (29355 views)
Shortcut
Re: [chassa2556] Multi-level Category Functions [In reply to] Can't Post

 
Yes, that would be great!

-aev-


JH
User

Jan 7, 2009, 1:25 AM

Post #22 of 63 (28966 views)
Shortcut
Re: [aev] Multi-level Category Functions [In reply to] Can't Post

hi Dave

I would like to creat my category with CSS and Table like below:
> Product 1
--------------------------------------
>Product 1-1
>Product 1-2
--------------------------------------
> Product 2

but now my Category in each table and have blank line like here:
> Product1
-----------------------------------
<----blank line
> Product1-1
-----------------------------------
<----blank line
> Product1-2
-----------------------------------
> Product 2


Here is my code below:

<?php foreach ($categoryRecords as $categoryRecord): ?>
<?php echo str_repeat("&nbsp; &nbsp; &nbsp;", $categoryRecord['depth']); ?>
<?php if ($categoryRecord['_isSelected']): ?>
<span class="sidebar">
<?php endif; ?>
</span>
<table border="0" cellpadding="5" cellspacing="2">
<tr>
<td class="sidebar" onmouseover="this.style.backgroundColor='#D0D7E1';" onmouseout="this.style.backgroundColor='';" valign="top"><!-- /category menu --><a href="<?php echo $categoryRecord['_link'] ?>" class="sidebar"><?php echo $categoryRecord['name'] ?></a></td>
</tr>
<tr>
<td class="sidebar" onmouseover="this.style.backgroundColor='#D0D7E1';" onmouseout="this.style.backgroundColor='';" valign="top"><img src="images/blue-page/sidebar-line.gif" width="140" height="1" /></td>
</tr>
</table>
<?php if ($categoryRecord['_isSelected']): ?>
<?php endif; ?>
<?php endforeach; ?>

Do you know how to solve the problem?

How you can help me.
Thanks a lot!!

-JH


Dave
Staff / Moderator


Jan 7, 2009, 4:23 PM

Post #23 of 63 (28938 views)
Shortcut
Re: [JH] Multi-level Category Functions [In reply to] Can't Post

Hi JH,

It's hard to tell from the code alone. Are you able to post an url to the page in question?

Generally, the first step is to create an html mockup that shows the category menu how you want it. It's much easier to debug html in an html only file.

Once that is working we can compare the code from the html mockup and the CMS generated code and see what we need to change.

If you can post urls to both that would be very helpful.

Dave Edis - Senior Developer
interactivetools.com
 


aev
User

Jan 14, 2009, 2:23 PM

Post #24 of 63 (28794 views)
Shortcut
Re: [Dave] Multi-level Category Functions [In reply to] Can't Post

Hi Dave,

can we limit the depth for a category section, like we can in AM?

With most designs we need to limit how many levels our clients can create.

-aev-


Dave
Staff / Moderator


Jan 14, 2009, 3:28 PM

Post #25 of 63 (28792 views)
Shortcut
Re: [aev] Multi-level Category Functions [In reply to] Can't Post

No, unfortunately there's currently no way to limit the depth.

Dave Edis - Senior Developer
interactivetools.com
 

First page Previous page 1 2 3 Next page Last page  View All