Forums / Cotonti / Support / How to show all categories and its sub categories in the list?

foxhound
#1 2014-02-25 15:31

I am trying to figure out a way to ouput all categories in the list section of my website.
So, say I have a news section and in that news section I have 5 categories and each of those categories has 4 sub categories I want to display all those categories in my list, no matter which "level" of the list you are viewing, it should output all categories of this news section all the time.


I tried to use pagelist plugin but that (obviously) is created to output pages within specific categories.
I looked at the http://www.cotonti.com/extensions/navigation-structure/catindex - 
Category Index plugin but that is build for Genoa and works on the index instead.
I tried to made it work with the http://www.cotonti.com/extensions/navigation-structure/table-of-contents TOC plugin but that plugin seems to have been build without the thought of a dropdown possibility.
The TOC plugin seems to be able to do what I need but it outputs a text list (like here: http://www.cotonti.com/docs/ ) and I would like to make it work with a dropdown. So, it should not show all the text by default but use the styling I would like to use instead (my specific dropdown nav menu). I have been trying to make it work but I think the php code interferes with any list styling you want to apply.

I hope someone can tell me how I could do this or maybe there is an easier way?

<img src="http://www.armaholic.com/datas/thumbs/green-sea-battalion-uniforms-version-03-preview_4.jpg" alt="green-sea-battalion-uniforms-version-03-" />
Macik
#2 2014-02-27 11:50

Here it is:

function catlist($tpl = 'catlist', $items = 0, $order = '', $cat = '', $sub = true)
{

	// Specific cat
	$cats = cot_structure_children('page', $cat, (bool)$sub,false);
	$t = new XTemplate(cot_tplfile($tpl, 'plug'));

	$totalitems = sizeof($cats);
	if (!$order) shuffle($cats);
	if ($items) {
		$cats = array_slice($cats,0,$items);
	}
	foreach ($cats as $idx => $cat_name) {
		$t->assign('CAT',$structure['page'][$cat_name]);
		$t->assign('cat_name',$cat_name);
		$t->parse('MAIN.CAT_ROW');
	}

$t->parse();
return $t->text();
}

I use this function for my own. It similar to pagelist but more simplier. You can add it to `global` hook  — for example simply add it to `pagelist.global.php` file.

 

https://github.com/macik
правильный хостинг — https://goo.gl/fjCa1F
foxhound
#3 2014-02-27 14:05

Thanks for that!!
That seems to properly output my structure of the specific section. :))

But, what would I need to add to your above code if I also want to "get" the cat title (of each category) and the cat description (of each category)?

And, how can I create a dropdown with that? Cause now it just outputs all categories (as well as sub categories if you set that to true) as text but I would like to show the sub categories only if you hover over like a navigation menu (so the main categories show by default and the subs only when you hover).
Since only CAT_NAME is a tag you can use I can not see a way to show the subcategories only on hover.
Maybe I need a additional tag for the sub categories?

 

<img src="http://www.armaholic.com/datas/thumbs/green-sea-battalion-uniforms-version-03-preview_4.jpg" alt="green-sea-battalion-uniforms-version-03-" />
Macik
#4 2014-02-27 22:26

First of all — I forget to add 

global $structure;

in the beginning of function.

Than you can use CAT tpl variable like:

CAT.path
CAT.tpath   
CAT.rpath   
CAT.id   
CAT.tpl  
CAT.title  
CAT.desc    
CAT.icon    
CAT.locked    
CAT.count      
CAT.onindex    
CAT.image    

 

 

https://github.com/macik
правильный хостинг — https://goo.gl/fjCa1F
foxhound
#5 2014-02-27 23:04

Thanks again! That sure gave me a lot more options. :)


Still I have no idea how I can make the output of the structure show in a drop down menu.

Thing is, I would like to use 1 tpl to create this, but that same tpl will be called in different areas on the website and each contains a different page structure.
I would like to use just 1 tpl which does this job otherwise I could end up with 10 different tpl's and if I can just use 1 tpl to create my dropdown navigation menu I can prevent to have to edit 10 different tpl's in the future (and even more if I use it on multiple sites).

So, if you have any idea how I could make that work please let me know, I would really appreciate it.
If it helps I can add the dropdown css here so you can see what kind of dropdown I am actually trying?

<img src="http://www.armaholic.com/datas/thumbs/green-sea-battalion-uniforms-version-03-preview_4.jpg" alt="green-sea-battalion-uniforms-version-03-" />
Macik
#6 2014-03-01 14:18

Not clearly understand what you speak about…  Trying to answer anyway.

You had one `catlist.tpl` tpl placed in `themes/plugins`. (see it below). Than you put TPL callback in your dropdown menu code (in `header.tpl` or wherever it had been placed):

{PHP|catlist('catlist',0,'','root_category_name')}

or 

{CAT_NAME|catlist('catlist',0,'','$this')}

catlist,tpl:

<!-- BEGIN: MAIN -->
<div class="dropdown">
	<ul class="dropdown-menu custom" role="menu" aria-labelledby="dropdownMenu_{CAT_TITLE}">
<!-- BEGIN: CAT_ROW -->
		<li class="subitem" role="presentation"><a role="menuitem" tabindex="-1" href="{cat_name|cot_url('page','c=$this')}">{CAT.title} </a></li>
<!-- END: CAT_ROW -->
</ul>
</div>
<!-- END: MAIN -->

 

 

 

https://github.com/macik
правильный хостинг — https://goo.gl/fjCa1F
foxhound
#7 2014-03-02 16:09

Yes, that is what I am trying but it always output all categoeires and subcategories in my menu. It does not show the subcategoeries on hover, it just adds them like a normal category.
I added the following to my catlist.tpl: 

<!-- BEGIN: MAIN -->
<div id="navigation" class="navigation">
    <ul>
<!-- BEGIN: CAT_ROW -->
        <li><a href="index.php?e=page&c={CAT_NAME}">{CAT_NAME}</a>
        	<ul class="sub-menu">
			<li><a href="index.php?e=page&c={CAT_NAME}">{CAT_NAME}</a></li>
    		</ul>
        </li>
<!-- END: CAT_ROW -->
</ul>
</div>
<!-- END: MAIN -->

 

But what it does is just create a dropdown for every item in the category and the dropdown will be the item itself. One big mess.
If you want I can show it on my test website so you can see what is happening (sent me a PM cause I would need to allow your IP!). Or I can paste all css and coding here. I really do not get it how I can make this work :(

<img src="http://www.armaholic.com/datas/thumbs/green-sea-battalion-uniforms-version-03-preview_4.jpg" alt="green-sea-battalion-uniforms-version-03-" />
Macik
#8 2014-03-02 23:22

With this simple function (`catlist`) you can not build complete category tree structure as it prints plain list of categories. So there are 3 ways to solve that:

  1. use plain list out put with path data, and code some js script to trnsform this in complete subcategories menu.
  2. if your structure are not very big and static, you can build completed menu tree with several calls of `catlist` function for different root catagories, placed it (manually) on propper level of you menu structure
  3. write own catlist function to process `$structure` list as multilivel tree
https://github.com/macik
правильный хостинг — https://goo.gl/fjCa1F
foxhound
#9 2014-03-04 12:08

Okay, thanks for all your help. :)

<img src="http://www.armaholic.com/datas/thumbs/green-sea-battalion-uniforms-version-03-preview_4.jpg" alt="green-sea-battalion-uniforms-version-03-" />