Short question: how do you use JS/jquery to return index of an element within some , given its class name?
Long question: I've been at this problem for a few hours and I can't seem to find a solution. I have a Wordpress site, which uses a theme that utilizes superfish and lavalamp jquery. the lavalamp works fine for categories and pages, but for a single post, the lavalamp keeps going to the first item of the list.
It's worth noting that I have done some serious googling around, but the answers are either too old, or they don't work for my case. I have jQuery 1.7.1, lavaLamp 1.3.3 (updating to 1.3.5 breaks everything), and superfish 1.4.8.
I've narrowed it down that the script that calls the lavaLamp plugin isn't returning the correct index of the current category for a single post. Here's what it looks like:
var active_subpage = jQuery('ul.sf-menu ul li.current-cat, ul.sf-menu ul li.current_page_item').parents('li.top-level').prevAll().length;
var isHome = <?php if (is_front_page() || is_home()) echo('1'); else echo('0'); ?>;
if (active_subpage) jQuery('ul.sf-menu').lavaLamp({ startItem: active_subpage });
else if (isHome === 1) jQuery('ul.sf-menu').lavaLamp({ startItem: 0 });
else jQuery('ul.sf-menu').lavaLamp();
How do I modify the script so that it returns the index of the "current-cat" for that post?
I've pasted what I think you'd need HERE. You can take a look at the live site HERE.
Thank you very much in advance!