X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   amazon-style tabbed menu for 4.0.x (https://forum.x-cart.com/showthread.php?t=11567)

steveparks 01-19-2005 02:03 PM

amazon-style tabbed menu for 4.0.x
 
Ok, this is a big moment for me....like going to the pub for your first pint with your dad.

After a while of being completely x-cart ignorant, although extremely well looked after by Shan, I have been teaching myself Smarty, PHP etc, and have now developed my first x-cart mod!

So, bear in mind I'm a complete noob and please don't laugh at my foolish mistakes.

But I hope this proves useful to some people, and acts as a starting point for the experts among you to turn this into something really cool!

I wanted to share it to say thanks to everyone who has shared code on this forum so far, you've helped me learn x-cart!

This mod is for 4.0.x
------------------------

What I wanted to create was a horizontal tab menu, based dynamically on the categories. It should know which category you're in, and display subcategories below the tabs, as well as highlighting the currently active tab. It should also be simple, and accessible to as many browsers as possible - and accessible to as many people as possible - so none of those naughty tab images like amazon itself!

Here's how to implement it:

1. Create 3 sets of tab side images.

Make them 10x20, and store them in your skin1/images folder.

Call them:
left-tab.gif
right-tab.gif
left-tab-hover.gif
right-tab-hover.gif
left-tab-active.gif
right-tab-active.gif

or you can nick these:
http://www.redshop.biz/skin1/images/left-tab.gif
http://www.redshop.biz/skin1/images/right-tab.gif
http://www.redshop.biz/skin1/images/left-tab-hover.gif
http://www.redshop.biz/skin1/images/right-tab-hover.gif
http://www.redshop.biz/skin1/images/left-tab-active.gif
http://www.redshop.biz/skin1/images/right-tab-active.gif


2. Add this CSS code to your skin1/skin1.css file:

Code:


.tabmenuitem
{
        font-size: 1em;
        text-transform: lowercase;
        font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
        font-weight: bold;
        line-height: 1.5em;
        height: 1.5em;
        cursor: hand;
}
.tabmenuitemon
{
        font-size: 1em;
        text-transform: lowercase;
        font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
        font-weight: bold;
        line-height: 1.5em;
        height: 1.5em;
        cursor: pointer;
}
.tabmenuitem a, .tabmenuitem a:link, .tabmenuitem a:visited
{
color: #000000;
background: #CCCCCC url("images/left-tab.gif") left top no-repeat;
height: 1.5em;
text-decoration: none;
padding-left: 10px;
line-height: 1.5em;
}
.tabmenuitemon a, .tabmenuitemon a:link, .tabmenuitemon a:visited
{
color: #e32c2c;
background: #ECEFF3 url("images/left-tab-active.gif") left top no-repeat;
height: 1.5em;
text-decoration: none;
padding-left: 10px;
line-height: 1.5em;
}
.tabmenuitem a span, .tabmenuitem a:link span, .tabmenuitem a:visited span
{
background: url("images/right-tab.gif") right top no-repeat;
height: 1.5em;
line-height: 1.5em;
padding-right: 10px
}
.tabmenuitemon a span, .tabmenuitemon a:link span, .tabmenuitemon a:visited span
{
background: url("images/right-tab-active.gif") right top no-repeat;
height: 1.5em;
line-height: 1.5em;
padding-right: 10px
}
.tabmenuitem a, .tabmenuitem a span, .tabmenuitem a:link span, .tabmenuitem a:visited span
{
display: block;
float: left
}
.tabmenuitemon a, .tabmenuitemon a span, .tabmenuitemon a:link span, .tabmenuitemon a:visited span
{
display: block;
float: left
}
/* Commented backslash hack hides rule from IE5-Mac \*/
.tabmenuitem a, .tabmenuitem a span, .tabmenuitem a:link span, .tabmenuitem a:visited span
{
float: none
}
.tabmenuitemon a, .tabmenuitemon a span, .tabmenuitemon a:link span, .tabmenuitemon a:visited span
{
float: none
}
/* End IE5-Mac hack */

.tabmenuitem a:hover
{
color: #ECEFF3;
background: #e32c2c url("images/left-tab-hover.gif") left top no-repeat;
height: 1.5em;
text-decoration: none;
padding-left: 10px
}
.tabmenuitemon a:hover
{
height: 1.5em;
text-decoration: none;
padding-left: 10px
}

.tabmenuitem a:hover span
{
background: url("images/right-tab-hover.gif") right top no-repeat;
height: 1.5em;
padding-right: 10px
}
.tabmenuitemon a:hover span
{
height: 1.5em;
padding-right: 10px
}
.submenu
{
        BACKGROUND-COLOR: #ECEFF3;
}
.submenuitem, .submenuitem a, .submenuitem a:link, .submenuitem a:visited
{
        font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
        font-size: 0.9em;
        text-transform: lowercase;
        color: #000000;
}
.submenuitemon, .submenuitemon a, .submenuitemon a:link, .submenuitemon a:visited
{
        font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
        font-size: 0.9em;
        text-transform: lowercase;
        color: #e32c2c;
}
.submenuitem a:hover
{
        color: #e32c2c;
}
.submenuitemon a:hover
{
        color: #e32c2c;
        text-decoration: none;
}
.submenumsg
{
        font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
        font-size: 0.8em;
        font-style: normal;
        text-transform: lowercase;
        color: #000000;
        letter-spacing: 0.04em;
}



3. Create a file called 'skin1/customer/tab_menu.tpl'

Code:

{if $printable ne ''}
{include file="customer/tab_menu_printable.tpl"}
{else}
<TABLE width="100%" border="0" cellpadding="0" cellspacing="0">
<TR><TD align="center">
<TABLE border="0" cellpadding="0" cellspacing="0">
<TR>
{if $cat eq 0}
<TD align="center" class="tabmenuitemon" nowrap><span>home</span>
</TD>
{else}
<TD align="center" class="tabmenuitem" nowrap><span>home</span>
</TD>
{/if}
{section name=cat_num loop=$categories}
{if $categories[cat_num].order_by lt 10}
{if $cat eq $categories[cat_num].categoryid || $current_category.parentid eq $categories[cat_num].categoryid}
<TD align="center" class="tabmenuitemon" nowrap><span>{$categories[cat_num].category}</span>
</TD>
{else}
<TD align="center" class="tabmenuitem" nowrap><span>{$categories[cat_num].category}</span>
</TD>
{/if}
{/if}
{/section}
</TR>
</TABLE>
</TD></TR>
<TR><TD class="submenu" align="center" valign="top">
<TABLE border="0" cellpadding="0" cellspacing="0">
{assign var=current_category_top value=$current_category.categoryid_path|regex_replace:"/\/.*/":""}
<TR>
<TD class="submenuitem"></TD>
{if $cat gt 0}
{assign var=subcat_count value=1}
{section name=sub_num loop=$allcategories}
{if $allcategories[sub_num].parentid eq $current_category_top}
{if $allcategories[sub_num].categoryid eq $cat || $allcategories[sub_num].categoryid eq $current_category.parentid}
<TD class="submenuitemon" align="center" nowrap>{$allcategories[sub_num].category|truncate:20:"...":true}{if $subcat_count eq 7 || $subcat_count eq 14 || $subcat_count eq 21}</TD></TR></TABLE><TABLE border="0" cellpadding="0" cellspacing="0"><TR><TD class="submenuitem">{elseif not %sub_num.last%}<FONT class="submenuitem">|</FONT>{/if}</TD>
{assign var=subcat_count value=$subcat_count+1}
{else}
<TD class="submenuitem" align="center" nowrap>{$allcategories[sub_num].category|truncate:20:"...":true}{if $subcat_count eq 7 || $subcat_count eq 14 || $subcat_count eq 21}</TD></TR></TABLE><TABLE border="0" cellpadding="0" cellspacing="0"><TR><TD class="submenuitem">{elseif not %sub_num.last%}|{/if}</TD>
{assign var=subcat_count value=$subcat_count+1}
{/if}
{/if}
{/section}
{else}
<TD class="submenumsg" align="center" valign="middle">{$lng.lbl_welcome_msg}</TD>
{/if}
<TD class="submenuitem"></TD>
</TR>
</TABLE>
</TD></TR>
</TABLE>
{/if}



5. Create a new language label through the admin interface.

'lbl_welcome_msg' is for a short welcome message about your store, to be displayed when the user is not within a category. You can have this as an empty string.


6. Alter 'head.tpl'

Take a back up first, then, just before the first bit of code that looks like this:

Code:

<TR>
<TD  colspan="2" class="VertMenuBorder">[img]{$ImagesDir}/spacer.gif[/img]</TD>
</TR>


Add in this:
Code:

<TR>
<TD colspan="2" align="center">
{ include file="customer/tab_menu.tpl" }
</TD>
</TR>


And that should (fingers crossed) work!

You can see it in action at my development store at:

http://www.redleader.biz/xcart/home.php


Thankyou, and any improvements and ideas welcome.

EDITS MADE SINCE FIRST POST
20.01.05 15.00GMT : Added code so that the top tabs are only generated for categories with an 'order by' value of less than 10. So you can have only your main categories on the horizontal tab menu, with all your categories in your vertical categories menu.
10.01.05 15.14GMT : Added 'cursor' paramaters to the CSS as suggested by PhilJ, because IE wasn't showing correct cursor.
14.02.05 23.40GMT : Improved display of subcategories, so the first level of subcategories stay in place as you go into a product or one category further down. Generally improved code a little.
03.04.05 14.25GMT : Updated tab_menu.tpl to better manage the subcategories sub menu. It now truncates long names, and wraps onto more than one line if there are lots of subcats. I also improved the way that it creates the subcategories menu, so that it will keep the first level of subcategories displayed, however deep down into sub-sub-sub-categories you are! (Thanks to fernando for making a post elsewhere that helped me with this).

The next tasks for me on this mod are:
1. change so that the subcategories under the tabs always stay as the 1st set of subcategories of the path you are in, no matter how many levels down you are.
2. Tidy up the code a bit more.

donavichi 01-19-2005 03:16 PM

well done, mate, that's wicked!

It's not quite perfect in that it seems to switch from square to rounded corners when you roll the mouse over but I'm sure you'll be on the case and modify the code above when you're done...

I've always wondered how to implement a menu like that. Thanks

steveparks 01-19-2005 03:46 PM

Thanks
 
Thanks

Which browser do you use?

I've tested in Firefox 1.0 and IE6 so far, and it worked fine for me in both of those.

I'd appreciate feedback from people with other browsers, and older versions of IE - and advice on how to make this as cross browser compliant as posssible!

There is still a bit of work to make it work at its best in IE, but it works 100% in firefox.

donavichi 01-19-2005 05:15 PM

I'm on IE6, Windows XP SP2.

Let me know as you update and I'll gladly test it out.

Regards,

hooter 01-19-2005 06:31 PM

Very nice Steve - great job 8)

And I am using Firefox 1.0 as well - no issues that I could see.

steveparks 01-20-2005 12:13 AM

IE problems
 
Thanks hooter!

Donavichi...I've managed to replicate the problem you highlight on another machine. (my machine is IE6 WinXPSP2 as well though, so i don't know why thats different?!?!).
It seems that for the first page or two IE doesn't switch the tab images quickly enough...but after that it gets on fine with them.

Anyone got any ideas as to how to fix this (let alone why IE can't cope with it!)?

Thanks
Steve

PhilJ 01-20-2005 05:46 AM

Well done, thanks for sharing the code =D>

Might wanna change the link cursor style to "hand".

I always wondered how to mimic the menu at www.play.com

steveparks 01-20-2005 05:56 AM

play.com
 
Thanks PhilJ

I've just been to have a look at play.com - they use images (and they don't even use alt tags!!) So that means their menu is inaccessible to people with sight impairments.
It also means that the menu doesn't automatically update if they add categories or change the names.

With my menu, if you increase the text size the menu grows with it and doesn't break - so it works if people need very large print on the screen.It should also work in screen readers.

My aim was to have a really accessible menu - and one that didn't rely on javascript.

It also updates automatically from the categories in the DB, so doesn't need any maintenance.

steve

PhilJ 01-21-2005 03:00 PM

Excellent, fair shout for making it more accessible. I can see this becoming a very popular mod.

jdedba 01-22-2005 01:44 PM

Steve,

Thank you very much for sharing the mod.

Today I went to the file download area in X-cart Support and realized the 4.0.11 has been released.

So I just installed a fresh 4.0.11 version with demo data, and then followed your steps to inplement you tab mod. I only get the Home tab shows up. If I click on a category on the left-hand Categories menu, the subcategories show up under the Home tab, but the selected category still does not show up on the tab. Do I need to turn on something in the Admin area to make it work?

Or does somebady know there is a change in version 4.0.11 on defining these x-cart cat variables?

Very nice mod. I really like it.

Regards,

Jeff

jdedba 01-22-2005 03:47 PM

Ok, I found my problem. I am not sure what .order_by presents, but if I change 10 to 50 or comment the below line out, the main categories shows up on the tab.

Code:

{if $categories[cat_num].order_by lt 10}

So, if there are too many categories, the tab will be too wide. Can put the menu into two rows?

I am still trying two problems:

1. If I want to add an additional tab to the menu, the color change will not be right. For example, add below line to the tab_menu.tpl

<TD align="center" class="tabmenuitem" nowrap><span>Test</span>
</TD>

2. Once I click on a subcategory, the red color on the text of subcategroy will be kept. I guess it can be fixed by css file, but donot know how yet.

Thanks again.

Jeff

steveparks 01-25-2005 02:02 AM

explanation
 
Just to clarify to everyone:

1. Order_by
order_by is the numeric value that you can assign to each category from the admin area in x-cart. That value determines in which order the categories appear in the category menu.

Because you don't want there to be too many tabs in the tab menu, I've set it so that only Categories with an order_by of less than 10 will show up in the tabs - that way you can have only your most important categories on this key menu...and the rest on the side menu.

To decide which tabs appear in your tab menu, simply log in to your admin area, select 'Categories' from the menu on the left, and assign values of less than 10 to the categories you want to appear in the tab menu. They will appear in order of these numbers, so give the ones you want to be further on the left the lowest number.

This provides a simple method for you or your customers to control the tab menu without delving into code all the time.

Adding more tabs
The tabs (except the 'home' tab) are added dynamically from your category structure. You do not need to add any more code to add more tabs. Just give the categories an order_by value of less than 10.
If you really want to add more tabs to static pages or similar then you can do this in the code, but i'd advise having this on the speedbar, so that you can easily change or update them from the admin area. You can change the look and feel of the speedbar easily (see other posts in these forums), see www.redleader.biz/xcart/home.php (my development site) for an example.

[/b]

Danielle 01-27-2005 11:05 PM

I tried to implement this, but there was a square background behind the tab that matched whatever color I used on the tab itself. How do I get rid of that? Also, can I do it like on this site? www.wholefamilymarket.com? I really like how theirs are, and that is the kind of info I wanted on my tabs, I don't really want product categories, I just want them to be for additional info.

Thanks!

steveparks 01-27-2005 11:49 PM

Speed bar
 
Hi Danielle

It looks like they've just moved the speed bar, which is simple enough to do (search for 'speedbar' on this forum), then you can set what the tabs are from the admin backend.

Re: the square edges you're getting. it does seem to be a problem that IE doesn't load the corner images quickly enough. If you hold the mouse over a tab for a little bit, it will then load thee image, and it will be fine after that.
Anyone got any ideas for a workaround for this? Firefox handles it absolutely fine.

I have one idea which is to load the rollover images into the page on the page loading, with them just being allowed dimensions of 1x1. then IE should have them cached.
I'll try this over the weekend.
steve

aaron 01-28-2005 05:58 AM

different image for each category?
 
This is a nice mod, good job.

I am wondering if it is possible to add to it, what I am hopeing for is to have a unique image for each category (category icon), something that can be used in place of the text (then with the text as the alt tag)

Right now, as we are developing our store, we making a static menu across the top with a different image/rollover for each category. A dynamic category list like this would be more practicle, if we need to deactivate a category, we dont have physically remove the link,etc.

Would this be possible with this mod, or is there another mod that can accomplish this?

Thanks

Danielle 01-28-2005 06:23 AM

Hmmm nope mine never became rounded. You could see the rounded image over top of the square image. Whatever color I changed the tab too, that changed the background behind it. The square edges did not ever disappear.

steveparks 01-28-2005 10:21 AM

browser?
 
Hi Danielle

Could you let me know what OS, browser etc you were viewing it on please? I'll see if i can work out what was going on.

anyone else had this problem? anyone else got it working ok?

cheers
steve

Danielle 01-28-2005 10:25 AM

Hi, I am using Windows XP, IE6.

Thanks!
Danielle

steveparks 01-28-2005 10:30 AM

Images instead of text
 
Hi Aaron

What you want is possible.

In the code I posted above, look for:

Code:

{section name=cat_num loop=$categories}
{if $categories[cat_num].order_by lt 10}
{if $cat eq $categories[cat_num].categoryid}
<TD align="center" class="tabmenuitemon" nowrap><span>{$categories[cat_num].category}</span>
</TD>
{else}
<TD align="center" class="tabmenuitem" nowrap><span>{$categories[cat_num].category}</span>
</TD>


Then within each of the two TD tags, you will see:
Code:

{$categories[cat_num].category}

Change this (in both cases) to be:
Code:

[img]/CatIcons/{$categories[cat_num].category}.gif[/img]

Then create icons with exactly the same names as your categories, in a folder called CatIcons in the root directory. You can of course choose to use a Smarty variable to give the directory, and this would be best practice, but i use the directory above to illustrate.

You can also change what the images are called, so you could use categoryid or order_by or similar by changing the code above and the image name.

You can even tweak the code to have different images for whether a category is active or not.

cheers
steve

steveparks 01-28-2005 10:34 AM

XP IE6
 
Hi Danielle

I have IE6 and XP, and i can't seem to recreate the problem....they're just slow to load but they do appear.

Could you try out my development site, and see if you have the same issue with the tabs there please?
http://www.redleader.biz/xcart/customer/home.php

Thanks
Steve

aaron 01-28-2005 10:45 AM

Very nice.
Thanks alot

Danielle 01-28-2005 11:04 AM

I checked out your site last night and it looked great...

steveparks 01-28-2005 11:09 AM

thanks
 
Hi Danielle

Thanks!

In that case, its worth checking the code, and the CSS have copied across ok into your installation...it doesn't sound like a browser issue.

If you check against my first post in this forum, and make sure that nothings been missed out.

cheers
steve

mpj 02-14-2005 11:22 AM

Steve,

i'm having a slight issue on versoin 4.0.11

tab function work great and it displays the subcategory menu.

however, when i click on a link from the subcategory, the subcategory menu disappears.

also, i'm not sure how to do step # 5

5. Create a new language label through the admin interface.

'lbl_welcome_msg' is for a short welcome message about your store, to be displayed when the user is not within a category. You can have this as an empty string.

i want to do something like this, which i believe is from your code?

http://www.b4umovie.com/films/customer/home.php?cat=381


thanks again for such great work! excellent and clear code.

=D> =D> =D> !

steveparks 02-14-2005 02:28 PM

Updated code
 
Hi mpj

I'm afraid I can't claim any credit for the menu on the site you gave the link to - i think thats all their own work, as it funcctions differently to mine.

I've updated the code on my site, so I'll go and dig it out and update it in my first post above. That keeps the sub menu open when you go down below it - but at the moment only one more level - i'm trying to work out how to make it work however many levels you go down.

To do the step five, log into your admin interface. On the right hand side menu you'll see an option for Languages. click that, then select to edit the language you want.
Then scroll down the screen and you'll see a blank entry near the bottom. In the first box of this blank entry on the left enter 'lbl_welcome_msg', in the second box type some kind of note to rremind you what it is such as 'menu welcome message', and then in the third box enter the text you want to be displayed.
Then click add/submit/save (can't remember what the button says) and you've done it!

watch out for updated code in my first post soon. I'll put a note at the bottom of it when i've updated it.

mpj 02-14-2005 02:34 PM

hi Steve!

I'm trying to implement this code with your script. This would keep the current subcategory listed.

It's not my code, I got it from someone on this forum. Sorry I dont remember the original thread.

HTH.

Thanks for your kind reply.


Code:

{section name=cat_num loop=$categories}
{* Added by Fernando. Show first level of subcategories *}
{if $current_category ne "" }
  {section name=subcat loop=$allcategories}
{assign var=topmostcat value=$allcategories[subcat].categoryid_path|regex_replace:"/\/.*/":""}
{assign var=current_category_top value=$current_category.categoryid_path|regex_replace:"/\/.*/":""}
    {if $current_category_top eq $topmostcat and $categories[cat_num].categoryid eq $topmostcat and $allcategories[subcat].parentid eq $topmostcat and $allcategories[subcat].categoryid ne $current_category_top}
      {$allcategories[subcat].category|truncate:20:"...":true}

    {/if}
  {/section}
 {/if}
{* End added by Fernando *}


{/section}


steveparks 02-14-2005 02:46 PM

update done
 
Hi Mpj

I've now updated the code in my first post.

Thanks for posting that bit of code. I'll have a play with it.

Steve

mpj 02-14-2005 03:01 PM

code works like a charm on 4.0.11

many many thanks for a great code and programmer!

=D> =D> =D>

mpj 02-15-2005 11:15 AM

one last thing, css related, code works fine ! :)


Here is my CSS. It works fine in Firefox but IE doesn't seem to understand the "height: 20px" atrribute, under "A href " conditions.

My CSS
Code:

.submenuitem, .submenuitem a, .submenuitem a:link, .submenuitem a:visited
{
  font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
  font-size: 0.9em;
  text-transform: lowercase;
  color: #000000;
  height: 20px;



My HTML
Code:

Small Dog


<class="submenuitem">
Big Bird
</class>
-->


While using IE, the CSS woks for "Small Dog" and "Big Bird" but the CSS atribute " height: 20px; " would not show up for "Small Dog".

only " height: 20px;" doesn't show for "Small Dog", other attributes like hover, link, etc. are fine.

Please help.

Thanks

mpj 02-16-2005 10:52 AM

to answer my own question:

" <a>, is an inline element and does not take height or width dimensions. Probably what you want is {line-height: 20px;} "

:D

thanks gary!

KCAutosound 02-20-2005 11:25 PM

is there a way to limit the subcategories to 10? or even better just make the subcategories become two rows if say they are over 10.

mpj 02-21-2005 11:27 AM

display of category can be set by

Code:

{if $categories[cat_num].order_by lt 500} 

this refers the the category position list.



Steve,

Please check your PM as I have updated the code a bit, but just need to resolve one slight issue.

Thanks.

KCAutosound 02-21-2005 01:17 PM

Yes I realize that is how you limit the main categories but I want to limit the subcategories to a limit of 10 or so.

KCAutosound 02-22-2005 10:33 PM

anyone?

ian_fs 02-23-2005 02:57 AM

I am guessing here but you could try changing categories to subcategories

Code:

{if $subcategories[cat_num].order_by lt 500

Worth a try. I might be wrong.

mpj 02-23-2005 08:34 AM

use

Code:

{section name=cat_num loop=$categories max=10}


hth

mpj

KCAutosound 02-23-2005 09:37 AM

I can limit the main categories. That's no problem. Just change the {if $categories[cat_num].order_by lt 12} line to whatever number you want.

My situation is that I want to limit the subcategories that show up under the main category.

Check this out. It spreads my site out huge. http://www.kcautosound.com/store/home.php?cat=2 I need to limit the subcategories down to like ten. Sure I can just create another main category to pick up but would like to keep them all in the same main category.[/url]

mpj 02-23-2005 09:42 AM

Code:

{if $subcategories[sub_num].order_by lt 500}
<A href="home.php?cat={$subcategories[sub_num].categoryid}" class="submenuitem">
{$subcategories[sub_num].category}
</a>{if not %sub_num.last%} |{/if}
{else}{/if}


KCAutosound 02-23-2005 02:20 PM

Hey thanks. Got it to work. Also got it to show more than ten main categories without extending the whole screen. Thanks guys.

KCAutosound 02-23-2005 07:19 PM

well I spoke too soon. had it looking good with firefox but then I tested it with explorer and all the menus are in a straight line down...lol


All times are GMT -8. The time now is 05:26 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.