Multi-level Category Functions

63 posts by 17 authors in: Forums > CMS Builder
Last Post: December 19, 2011   (RSS)

By aev - January 20, 2009

Hi!

inside the categoryRecords there are two order values:

[globalOrder] => 7
[siblingOrder] => 5

What do they tell, what's the difference between them?

-aev-

Re: [aev] Multi-level Category Functions

By Dave - January 20, 2009

Hi Aev,

Probably the simplest way to get the first record right now would be to create a single page viewer that loads it. Then pass the number from the first record to the code you've written.

I can add that to the code to do it automatically in the future, though. We're just about to do a release for 1.24 and then I can work on that. Feel free to email me and we can discuss that more.

Once the category functions get refined a little more we'll add them to the code generator.

>[globalOrder] => 7
>[siblingOrder] => 5
>What do they tell, what's the difference between them?

These are internal fields. siblingOrder is the order of the nodes within a branch. globalOrder is the order of the branches within the category tree.

If you sort by globalOrder you'll get the records in the same order as they appear in the editor.

Hope that helps! :)
Dave Edis - Senior Developer
interactivetools.com

By Toledoh - June 24, 2009

Hi Guys,

I'm havng some problems here - maybe the brains just in overload :)

1. Error at top of page: http://www.forrest.id.au/nutsandbolts/categoryList.php

2. How can I add classes etc to the li's?. ie. I want to produce this;

<ul id="navigation">
<li>
<a class="head" href="#">Guitar</a>
<ul>
<li><a href="#">Electric</a></li>
<li><a href="#">Acoustic</a></li>
<li><a href="#">Amps</a></li>
<li><a href="#">Effects A</a></li>
<li><a href="#">Effects B</a></li>
<li><a href="#">Effects C</a></li>
<li><a href="#">Effects D</a></li>
<li><a href="#">Accessories</a></li>
</ul>
</li>

I've attached the categoryList.php

Cheers,
Cheers,

Tim (toledoh.com.au)
Attachments:

categorylist.php 2K

Re: [Toledoh] Multi-level Category Functions

By Dave - June 24, 2009

Hi Tim,

So you want to add a class to the anchor tag of the top level? Is that right? Or anywhere else as well?

You could try something like this in your <a> tag:

<?php if ($categoryRecord['depth'] == 0): ?>class="head"<?php endif ?>

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

By Toledoh - June 24, 2009

Thanks Dave - I'll give that a shot.

Any ideas on the error?

Cheers,
Tim
Cheers,

Tim (toledoh.com.au)

Re: [Toledoh] Multi-level Category Functions

By Dave - June 24, 2009

Not sure, do you want to send me CMS and FTP login details to dave@interactivetools.com and I can track it down and fix it for you? Note - email, don't post login details to the forum.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

By pcolvin - November 11, 2010

The only way I can get this to work is to comment out the following line in the Load Records code:

'selectedCategoryNum' => '', // defaults to getNumberFromEndOfUrl()

<?php

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
));

?>


Could something have changed from when this was originally posted? I'm running CMSB Ver. 2.06. I have tried a couple different things including a suggestion later in the post with no luck. The page seems to work well with the line commented out. I want to make sure it is not something that needs to be there for a reason that I am not seeing.

Thanks...

Re: [pcolvin] Multi-level Category Functions

By Dave - November 15, 2010 - edited: November 15, 2010

Hi pcolvin,

Yes you're right, something did change and you figured out the right solution for it.

We made a change so you could set selectedCategoryNum to zero when you didn't want anything selected, but it had the side affect that setting it to blank ('') also didn't select anything.

I've updated the code to fix that for future but just commenting out that line as you've done should work fine.

Let me know if you need any other help with this.
Dave Edis - Senior Developer
interactivetools.com

By mohabsi - December 12, 2010

Hi Dave

if i have accordion menu like that

<div class="glossymenu">
<a href="#" >fruit</a>
<div class="submenu">
<ul>
<li><a href="#" >apple</a></li>
<li><a href="#" >orage</a></li>
</ul>
</div>

<a href="#" >vegetables</a>
<div class="submenu">
<ul>
<li><a href="#" >potato</a></li>
<li><a href="#" >tomato</a></li>
</ul>
</div>

</div>


How can I use category to solve that

Re: [mohabsi] Multi-level Category Functions

By Chris - December 14, 2010

Hi mohabsi,

Try adding this code at the bottom of your STEP 1:

$categoryHtml = array(
// rules for depth = 0
array(
'item_start' => '',
'sub_list_start' => '<div class="submenu"><ul>',
'sub_list_end' => '</ul></div>',
'item_end' => ''
),
// rules for any greater depths
array(
'item_start' => '<li>',
'sub_list_start' => '<ul>',
'sub_list_end' => '</ul>',
'item_end' => '</li>'
),
);

generateCategoryStartAndEndTags($categoriesRecords, $categoryHtml);

function generateCategoryStartAndEndTags(&$records, $html) {
$currentDepth = 0;
array_push($records, array('depth' => 0));
for ($i = 0; $i < sizeof($records); $i++) {
$records[$i]['_listItemStart'] = '';
$records[$i]['_listItemEnd'] = '';

// close item unless we'll be increasing depth (in which case, we'll close it when the depth returns to this level)
if ($currentDepth <= $records[$i]['depth']) {
$records[$i]['_listItemEnd'] .= $html[min($currentDepth, sizeof($html)-1)]['item_end'];
}

// close lists and items as we decrease depth
for (; $currentDepth > $records[$i]['depth']; $currentDepth--) {
$records[$i-1]['_listItemEnd'] .= $html[min($currentDepth - 1, sizeof($html)-1)]['sub_list_end'];
$records[$i-1]['_listItemEnd'] .= $html[min($currentDepth - 1, sizeof($html)-1)]['item_end'];
}

// open lists as we increase depth (this will only ever happen once at a time)
for (; $currentDepth < $records[$i]['depth']; $currentDepth++) {
$records[$i]['_listItemStart'] .= $html[min($currentDepth, sizeof($html)-1)]['sub_list_start'];
}

// open an item every time we display an item
$records[$i]['_listItemStart'] .= $html[min($currentDepth, sizeof($html)-1)]['item_start'];

}
array_pop($records);
}


You will likely need to change the name of your categories variable to match your section name, shown in red above.

Does that help? Please let me know if you have any questions.
All the best,
Chris