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


aev
User

Jan 14, 2009, 11:11 PM

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

Could you please add that to your CMSB feature request list.. Smile

We recently started using these menus and would very much like to limit their depth.

-aev-


Dave
Staff / Moderator


Jan 15, 2009, 2:58 PM

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

Sure, added. Hopefully in the next few versions.

Dave Edis - Senior Developer
interactivetools.com
 


aev
User

Jan 19, 2009, 2:08 PM

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

Hi!

According to the opening post in this thread, we are using this code to load a category section:


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


The problem with this code is that it doesn't put anything inside $selectedCategory if there is no "number at end of URL". We would like $selectedCategory to be the first record in the $categoryRecords array when there is no number in the URL.

How can we do that?

Isn't $selectedCategory more like a "selectedRecord"?

We would really appreciate more documentation on how to configure Category section, like we have for other type of sections here:
http://www.interactivetools.com/docs/cmsbuilder/viewer_options.html

-aev-


Dave
Staff / Moderator


Jan 19, 2009, 3:56 PM

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

Hi Aev,

Try this quick fix. Add this code above the code you posted:

$selectedCategoryNum = getNumberFromEndOfUrl();
if (!$selectedCategoryNum) { $selectedCategoryNum = 1; }

// set the number to the default category num you want selected.

Then change the option to this:

'selectedCategoryNum' => $selectedCategoryNum,

Let me know if that works for you.

Dave Edis - Senior Developer
interactivetools.com
 


aev
User

Jan 19, 2009, 10:06 PM

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

Hi Dave,

I'm sorry but this wasn't quite what I wanted to solve.

We already used this similar code, that did the same thing:

Code
if (!getNumberFromEndOfUrl()) { 
$catNum = 1;
} else {
$catNum = getNumberFromEndOfUrl();
}

The problem with this solution is that it uses a certain category number, like 1, as the default page when there is no number in the URL. We want to display whatever page our client put at the top in his category section, and that isn't necessary cat no. 1.

It's like we want to display $categoryRecords[0], but I don't know how to do that inside the list( getCategories()); function.

How can we do that?

-aev-


aev
User

Jan 19, 2009, 11:15 PM

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

Hi!

inside the categoryRecords there are two order values:

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

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

-aev-


Dave
Staff / Moderator


Jan 20, 2009, 11:15 AM

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

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
 


Toledoh
Enthusiast

Jun 23, 2009, 10:59 PM

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

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 Forrest
Toledoh Enterprises
www.toledoh.com.au
Attachments: categoryList.php (1.85 KB)


Dave
Staff / Moderator


Jun 24, 2009, 12:14 PM

Post #34 of 63 (14369 views)
Shortcut
Re: [Toledoh] Multi-level Category Functions [In reply to] Can't Post

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
 


Toledoh
Enthusiast

Jun 24, 2009, 2:32 PM

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

Thanks Dave - I'll give that a shot.

Any ideas on the error?

Cheers,
Tim
Cheers,

Tim Forrest
Toledoh Enterprises
www.toledoh.com.au


Dave
Staff / Moderator


Jun 24, 2009, 2:41 PM

Post #36 of 63 (14362 views)
Shortcut
Re: [Toledoh] Multi-level Category Functions [In reply to] Can't Post

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
 


pcolvin
User

Nov 11, 2010, 8:08 PM

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

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


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



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

?>


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...


Dave
Staff / Moderator


Nov 15, 2010, 9:53 AM

Post #38 of 63 (12814 views)
Shortcut
Re: [pcolvin] Multi-level Category Functions [In reply to] Can't Post

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
 

(This post was edited by chris on Nov 15, 2010, 2:12 PM)


mohabsi
User

Dec 12, 2010, 8:58 AM

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

Hi Dave

if i have accordion menu like that


Code
 
<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


Chris
Staff


Dec 14, 2010, 5:12 PM

Post #40 of 63 (12602 views)
Shortcut
Re: [mohabsi] Multi-level Category Functions [In reply to] Can't Post

Hi mohabsi,

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


Code
  $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.
Chris


mohabsi
User

Dec 15, 2010, 1:28 AM

Post #41 of 63 (12592 views)
Shortcut
Re: [chris] Multi-level Category Functions [In reply to] Can't Post

thank You chris

But i don't know how to display the result BlushBlushBlush


Chris
Staff


Dec 15, 2010, 10:04 AM

Post #42 of 63 (12581 views)
Shortcut
Re: [mohabsi] Multi-level Category Functions [In reply to] Can't Post

Hi mohabsi,

The code I posted overrides the usual _listItemStart and _listItemEnd psuedo-fields, so you'll want to display your category records normally:


Code
<div class="glossymenu"> 
<?php foreach ($categoryRecords as $categoryRecord): ?>
<?php echo $categoryRecord['_listItemStart'] ?>

<a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a>

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


Does that work for you?
Chris


mohabsi
User

Dec 15, 2010, 11:59 PM

Post #43 of 63 (12570 views)
Shortcut
Re: [chris] Multi-level Category Functions [In reply to] Can't Post

hi chris,

sorry i try the code but not work
i solve the problem with other way


Code
 
<div class="glossymenu">

<?php foreach ($categoryRecords as $categoryRecord): ?>
<?php if ($categoryRecord['depth'] == 0): ?>
<a href="<?php echo $categoryRecord['_link'] ?>" class="menuitem submenuheader"><?php echo $categoryRecord['name'] ?></a>
<?php $parent=$categoryRecord['num'];?>
<ul class="submenu">

<?php foreach ($categoryRecords as $categoryRecord): ?>
<?php if ($categoryRecord['parentNum'] == $parent): ?>
<li><a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a></li>
<?php endif ?>
<?php endforeach; ?>

</ul>
<?php endif ?>
<?php endforeach; ?>
</div>


and thanks again for your efforts


Chris
Staff


Dec 16, 2010, 3:10 PM

Post #44 of 63 (12521 views)
Shortcut
Re: [mohabsi] Multi-level Category Functions [In reply to] Can't Post

Hi mohabsi,

That's a clever solution, and I'm glad you got things working. :)

Any chance you could tell me what didn't work with my approach? I'm hoping that we can provide a function like the one I posted above to help others with similar requirements.
Chris


northernpenguin
User

Dec 27, 2010, 12:40 PM

Post #45 of 63 (12209 views)
Shortcut
Re: [chris] Multi-level Category Functions [In reply to] Can't Post

Chris: Is there any way to specify which category other than 0 to start with as the default?

Specifically, I want http://mywebsite.com/index.php to default to http://mywebsite.com/index.php?menu-number-five-2

Thanx

Ragi
--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke


Chris
Staff


Dec 28, 2010, 1:33 PM

Post #46 of 63 (12064 views)
Shortcut
Re: [northernpenguin] Multi-level Category Functions [In reply to] Can't Post

Hi Ragi,

Yes, there's a 'rootCategoryNum' option which will only list categories "under" the root. For example:


Code
  list($categoriesRecords, $selectedCategory) = getCategories(array( 
'tableName' => 'my_category_section',
'rootCategoryNum' => 2,
));


Does that help? Please let me know if you have any questions.
Chris


zip222
User

Dec 29, 2010, 12:12 PM

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

when using a category menu, how do I only show the sub menu items for the currently active section. example, here is a flat view of the menu I am working with...


Code
About 
- Company
- History
- Management
Products
- Product One
- Product Two
- Product Three
Services
- Service One
- Service Two
- Service Three


but what I want to do is only show the sub pages for the currently active section. and initially I only want to see the level 0 pages.

here is the code i am using for the menu shown above


Code
  <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>



Chris
Staff


Dec 29, 2010, 4:01 PM

Post #48 of 63 (11990 views)
Shortcut
Re: [zip222] Multi-level Category Functions [In reply to] Can't Post

Hi zip222,

I think the 'categoryFormat' => 'onelevel' option is what you're looking for:


Code
list($categoriesRecords, $selectedCategory) = getCategories(array( 
'tableName' => 'my_category_section',
'categoryFormat'=> 'onelevel',
));


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


zip222
User

Dec 30, 2010, 5:49 AM

Post #49 of 63 (11917 views)
Shortcut
Re: [chris] Multi-level Category Functions [In reply to] Can't Post

Yep, that's what I was looking for. Thanks.


Maurice
User

Jan 3, 2011, 6:45 AM

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

Hi dave,

I was playing around with this and got it working but some where i missed some thing/code the menu dos not link to the url/ location how do i set the right url to each menu item.

for instance i added a contact menu item with
this as result categoryList.php?Contact-11 how do i make a link to the right location /contact/index.php ???

thnx
Maurice
-------------------------------------------
www.intraserve.nl

Soon! cmsBy.intraserve

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