Post by eddy-r3 » Mon Jun 15, 2015 6:25 pm

Hi guys, im using a crude javascript in order to append an active class to my current category on the top menu.

I have added some "hard links" into header.tpl for "home" and "about us" from the information category. Now my Java looks like this :

Code: Select all

<script type="text/javascript">
var url = window.location.href;
$('#navbar a[href="'+ url +'"]').addClass('active');
</script>
But of course, this doesnt work for the hard linked items (home/about). Any ideas on getting this to work? Or at least, adding system generated links for home/about us into the top menu?

Thanks in advance!

Active Member

Posts

Joined
Tue Jan 31, 2012 4:46 am

Post by viethemes » Mon Jun 15, 2015 9:22 pm

You can try to replace with script below

Code: Select all

<script>
$('#menu a').each(function () {
	if (location.href.indexOf(this.href) > -1) {
		$(this).parents('#menu li').addClass('active');
	}
});
</script>
and apply class active for li elements of the top menu.

http://www.viethemes.com - OpenCart turtorials, news, tips and stricks, extension

Our extensions:
Visual Theme Editor - Powerful tool for customizing style of any theme visually
Live Theme Editor - Customize layout, colors, backgrounds, fonts of the default theme
Theme Animation - Animation Editor for any theme

Extra Positions PRO, Custom JavaScript, Custom CSS and others


User avatar
Active Member

Posts

Joined
Thu Jan 08, 2015 12:17 pm


Post by eddy-r3 » Mon Jun 15, 2015 9:34 pm

Excellent, thanks for the reply and the suggestion, i've added this, restyled my css to accomodate, and now its working on all of the links! BUT....no matter which page you go to, the Home item is always active as well as the current page...

Any suggestions? :)

Thanks a million!

Active Member

Posts

Joined
Tue Jan 31, 2012 4:46 am

Post by viethemes » Tue Jun 16, 2015 12:22 am

Could you provide your site URL, so we can take a look at it closer?

http://www.viethemes.com - OpenCart turtorials, news, tips and stricks, extension

Our extensions:
Visual Theme Editor - Powerful tool for customizing style of any theme visually
Live Theme Editor - Customize layout, colors, backgrounds, fonts of the default theme
Theme Animation - Animation Editor for any theme

Extra Positions PRO, Custom JavaScript, Custom CSS and others


User avatar
Active Member

Posts

Joined
Thu Jan 08, 2015 12:17 pm


Post by eddy-r3 » Tue Jun 16, 2015 12:48 am

Of course, http://sakhrjewellery.com/index.php

Thanks in advance! :)

Active Member

Posts

Joined
Tue Jan 31, 2012 4:46 am

Post by viethemes » Tue Jun 16, 2015 8:56 pm

Yes. You can try replacing code below

Code: Select all

<script>
$('#menu a').each(function () {
   if (location.href == this.href) {
      $(this).parents('#menu li').addClass('active');
   }
});
</script>

http://www.viethemes.com - OpenCart turtorials, news, tips and stricks, extension

Our extensions:
Visual Theme Editor - Powerful tool for customizing style of any theme visually
Live Theme Editor - Customize layout, colors, backgrounds, fonts of the default theme
Theme Animation - Animation Editor for any theme

Extra Positions PRO, Custom JavaScript, Custom CSS and others


User avatar
Active Member

Posts

Joined
Thu Jan 08, 2015 12:17 pm


Post by eddy-r3 » Tue Jun 16, 2015 11:08 pm

You're a gent and a scholar, thankyou! :)

Worked perfectly

Active Member

Posts

Joined
Tue Jan 31, 2012 4:46 am

Post by viethemes » Wed Jun 17, 2015 9:30 pm

You are welcome :)

http://www.viethemes.com - OpenCart turtorials, news, tips and stricks, extension

Our extensions:
Visual Theme Editor - Powerful tool for customizing style of any theme visually
Live Theme Editor - Customize layout, colors, backgrounds, fonts of the default theme
Theme Animation - Animation Editor for any theme

Extra Positions PRO, Custom JavaScript, Custom CSS and others


User avatar
Active Member

Posts

Joined
Thu Jan 08, 2015 12:17 pm

Who is online

Users browsing this forum: No registered users and 5 guests