Turning Catagories Into A drop down menu

Skinning and designing Serendipity (CSS, HTML, Smarty)
Post Reply
anannsul
Regular
Posts: 20
Joined: Thu Sep 25, 2008 5:31 am

Turning Catagories Into A drop down menu

Post by anannsul »

To clarify I do not want to include catagories plug into a drop down menu. i want it to BE the drop down menu.

Catagory
--sub catagory
--sub catagory
catagory

with the sub catagories being only visible when the catagory is hovered over.

Is this possible?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Turning Catagories Into A drop down menu

Post by garvinhicking »

Hi!

You can enable the smarty templating options of the category plugin and then edit your template's plugin_category.tpl template file. In there, instead of li/checkbox elements you could turn them into options...

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: Turning Catagories Into A drop down menu

Post by yellowled »

garvinhicking wrote:In there, instead of li/checkbox elements you could turn them into options...
... or a neat CSS/JS-based dropdown menu like Son of Suckerfish.

YL
anannsul
Regular
Posts: 20
Joined: Thu Sep 25, 2008 5:31 am

Re: Turning Catagories Into A drop down menu

Post by anannsul »

Where do I get this son of suckerfish? Just google it?

and also, I do not understand how to edit the category.tpl
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: Turning Catagories Into A drop down menu

Post by Don Chambers »

anannsul wrote:Where do I get this son of suckerfish? Just google it?

and also, I do not understand how to edit the category.tpl
Yes, there are many different "suckerfish" navigation bar/drop down examples out there.... but I get the feeling you are looking for an option list, not a navigation list.
=Don=
anannsul
Regular
Posts: 20
Joined: Thu Sep 25, 2008 5:31 am

Re: Turning Catagories Into A drop down menu

Post by anannsul »

No, want the navigation....

Like here http://www.htmldog.com/articles/suckerfish/dropdowns/

Only instead of going across the top it goes down in the sidebar.


The problem is I have no clue how to implement this into the category.tpl.

I only see one ul tag and one li and apparently it controls all of lists no matter how many levels there are.

=\
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: Turning Catagories Into A drop down menu

Post by Don Chambers »

It is not going to be easy, but it can probably be done...

The smarty template contains a variable called {$plugin_category.catdepth}. For a top level category, that value will be 0. First level child will be 1, second will be 2, and so on. So, for each iteration of the foreach loop, you will need some way of comparing that catdepth to the last one. If they are not the same, then you will need to open a new ul for the nested subcategory. I think you will also need some way to know that you have opened a new ul too. Then when it changes again, you need to know if it is due to returning to the parent level, or opening a grandchild category (3rd level) and act accordingly.

At least, that's my first thought.... and my first thoughts are not often my best. :lol:

Sounds like more of a PITA than it is worth. :mrgreen:
=Don=
anannsul
Regular
Posts: 20
Joined: Thu Sep 25, 2008 5:31 am

Re: Turning Catagories Into A drop down menu

Post by anannsul »

I got the variable...

I'm messing around with if statements but it's just not working out. lol. However, I haven't reached that point of giving up yet... so as of right now i'm open to any ideas on how to get this working.

I don't know what code would get it to compare or know that it's opened a new ul tag

Right now i have
ul
foreach
If cat depth== 0
li

else

ul
li
/li
/ul
/if
/li
/foreach
/ul

But that isn't what I want either.. because as you can tell.. if it isn't 0 then it gets it's own ul and li tags. lol. and for some reason the cat depth 0 is ending it's li before the else statement. =\
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: Turning Catagories Into A drop down menu

Post by Don Chambers »

I think you will get it figured out as it sounds like you are already on your way. Feel free to post actual code, and enclose it in code brackets.
=Don=
anannsul
Regular
Posts: 20
Joined: Thu Sep 25, 2008 5:31 am

Re: Turning Catagories Into A drop down menu

Post by anannsul »

Is there a variable to use in category.tpl that could check if the category is a parent or not?
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: Turning Catagories Into A drop down menu

Post by Don Chambers »

anannsul wrote:Is there a variable to use in category.tpl that could check if the category is a parent or not?
Not that I know of. Perhaps someone knows better than I. I think cat depth is your best bet.
=Don=
anannsul
Regular
Posts: 20
Joined: Thu Sep 25, 2008 5:31 am

Re: Turning Catagories Into A drop down menu

Post by anannsul »

I think I'm going to throw in the white flag. lol

taking out the check boxes and rss thing.. I get this as a base

Code: Select all

    <ul id="serendipity_categories_list" style="list-style: none; margin: 0px; padding: 0px">
{foreach from=$categories item="plugin_category"}
        <li class="category_depth{$plugin_category.catdepth} category_{$plugin_category.categoryid}" style="display: block;">
             <a href="{$plugin_category.categoryURL}" title="{$plugin_category.category_description|escape}" style="padding-left: {$plugin_category.paddingPx}px">{$plugin_category.category_name|escape}</a>
        </li>
{/foreach}
    </ul>
I have tried including an if statement just before the </li> tag

Code: Select all

 
<ul id="serendipity_categories_list" style="list-style: none; margin: 0px; padding: 0px">
{foreach from=$categories item="plugin_category"}
        <li class="category_depth{$plugin_category.catdepth} category_{$plugin_category.categoryid}" style="display: block;">
             <a href="{$plugin_category.categoryURL}" title="{$plugin_category.category_description|escape}" style="padding-left: {$plugin_category.paddingPx}px">{$plugin_category.category_name|escape}</a>
        {if $plugin_category.catdepth > 0}
<ul>
<li><a href="{$plugin_category.categoryURL}" title="{$plugin_category.category_description|escape}" style="padding-left: {$plugin_category.paddingPx}px">{$plugin_category.category_name|escape}</a>
</li>
</ul>
{/if}
</li>
{/foreach}
    </ul>   
But that gives every thing listed below that it's own ul tag for EVERY item in the parent category. So, I really don't know what to do anymore. lol.. and i'm not THAT great at php either. x.x

I saw this

Code: Select all

{if ($smarty.foreach.myloop.iteration) % 4== 0}</tr><tr>{/if}
but what that does is after the foreach loops 4 times it ends a cell and starts a new one... but I don't know if it's even possible to assign something like that to the {$plugin_category.catdepth}.

Like

Code: Select all

 {if $plugin_category.catdepth > 0} <ul> 
{foreach}
 <li><a href="{$plugin_category.categoryURL}" title="{$plugin_category.category_description|escape}" style="padding-left: {$plugin_category.paddingPx}px">{$plugin_category.category_name|escape}</a>
</li>
{/foreach}
</ul>
{/if}
but that doesn't work because when you look at the webpage and view the code
the parent somehow has the </li> after it anyway. >.<

._. I think this is way more advanced then what I know. :(
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: Turning Catagories Into A drop down menu

Post by Don Chambers »

I will look at this tomorrow, but perhaps someone else will respond prior to that. I am in Chicago, IL, USA and the Chicago Blackhawks won the Stanley Cup last night, and it has been a constant party since then, and I am - quite frankly - a little ....um... buzzed. :mrgreen: Also watching the NBA finals here, so I am fairly worthless at the moment!!! :lol: :lol: :lol:
=Don=
anannsul
Regular
Posts: 20
Joined: Thu Sep 25, 2008 5:31 am

Re: Turning Catagories Into A drop down menu

Post by anannsul »

:mrgreen: You party animal, you! lol

It's alright, thank you for all your help. :D
Post Reply