Hi,
Thank you in advance for your precious help.
I would like, if it is possible of course, the clicked button to be active and the category expanded (open) when the desired page is loaded in a new window -- when the visitor has clicked to consult all the items of the selected category.
Pleade find below the code:
<div id="menuCategories">
<ul class="topnav">
<?php $query_categories = mysql_query("SELECT * FROM " . categories . " WHERE parent_id=0") or die("" . $MySQLError . "");
while($row = mysql_fetch_array($query_categories)) { ?>
<li><?php echo '<a href="#">' . $row['category_name'] . '</a>'; ?>
<ul>
<?php $subQuery = mysql_query("SELECT * FROM " . categories . " WHERE parent_id =" . $row['category_id'] . " ORDER BY category_name ASC") or die("" . $MySQLError . "");
while ($subRow = mysql_fetch_array($subQuery)) { ?>
<li>
<?php if ($subRow['sub_sub_category'] == '0') {
echo "<a href=" . $url_product_list . "?category_id=" . $subRow['category_id'] . ">" . $subRow['category_name'] . "</a>";
} else if ($subRow['sub_sub_category'] == '1') {
echo '<a href="#">' . $subRow['category_name'] . '</a>';
$subsubQuery = mysql_query("SELECT * FROM " . categories . " WHERE parent_id =" . $subRow['category_id'] . " ORDER BY category_name ASC") or die("" . $MySQLError . "");
while ($subsubRow = mysql_fetch_array($subsubQuery)) { ?>
<ul>
<li><?php echo "<a href=" . $url_product_list . "?category_id=" . $subsubRow['category_id'] . ">" . $subsubRow['category_name'] . "</a>"; ?></li>
</ul>
<?php } } ?>
</li>
<?php } ?>
</ul>
</li>
<?php } ?>
</ul>
</div>
(function($){
$.fn.extend({
accordion: function(options) {
var defaults = {
accordion: 'true',
speed: 500,
closedSign: '<IMG alt="" src="../images/arrowOpen.png">',
openedSign: '<IMG alt="" src="../images/arrowClose.png">',
};
var opts = $.extend(defaults, options);
var $this = $(this);
$this.find("li").each(function() {
if($(this).find("ul").size() != 0){
$(this).find("a:first").append("<span>"+ opts.closedSign +"</span>");
if($(this).find("a:first").attr('href') == "#"){
$(this).find("a:first").click(function(){return false;});
}
}
});
$this.find("li.active").each(function() {
$(this).parents("ul").slideDown(opts.speed);
$(this).parents("ul").parent("li").find("span:first").html(opts.openedSign);
});
$this.find("li a").click(function() {
if($(this).parent().find("ul").size() != 0){
if(opts.accordion){
if(!$(this).parent().find("ul").is(':visible')){
parents = $(this).parent().parents("ul");
visible = $this.find("ul:visible");
visible.each(function(visibleIndex){
var close = true;
parents.each(function(parentIndex){
if(parents[parentIndex] == visible[visibleIndex]){
close = false;
return false;
}
});
if(close){
if($(this).parent().find("ul") != visible[visibleIndex]){
$(visible[visibleIndex]).slideUp(opts.speed, function(){
$(this).parent("li").find("span:first").html(opts.closedSign);
});
}
}
});
}
}
if($(this).parent().find("ul:first").is(":visible")){
$(this).parent().find("ul:first").slideUp(opts.speed, function(){
$(this).parent("li").find("span:first").delay(opts.speed).html(opts.closedSign);
$(this).parent("li").css('background-color', '#FFFFFF');
});
} else {
$(this).parent().find("ul:first").slideDown(opts.speed, function(){
$(this).parent("li").find("span:first").delay(opts.speed).html(opts.openedSign);
$(this).parent("li").css('background-color', '#CCCC33');
});
}
}
});
}
});
})(jQuery);