What is needed to make sidebar conditional?

LiteCart Fan
Şundan United Kingdom
Tem 2019 tarihinden beri üye

In templates/catalog/pages/category.inc.php

<div id="sidebar">

I don't need the category tree or recently viewed boxes and have removed them. However not all categories have filters and those products appear with the sidebar as a void on the side of the screen.

I was trying to edit the div line above to something like

<div id="sidebar" <?php if (this product has no filters) echo "class='no-filter';"?>  with the no-filter class in the css as display:none.

The problem is that I have no idea what to do/use for the  - this product has no filters - condition.

Can anybody help?

Thanks in anticipation

Dave

Moderator
Şundan Lithuania
Mar 2016 tarihinden beri üye

What are you trying to do? Hide sidebar completely if there are no filters?

Add this to category page then.


if($('.box.attributes').length == 0){
   $('#sidebar').hide();
}
</script>```
LiteCart Fan
Şundan United Kingdom
Tem 2019 tarihinden beri üye

dodo, Tim

Many thanks for your replies.

I perhaps failed to explain what I was trying to achieve properly and absolutely failed to understand the underlying skelton of the template.

I had already commented the code that drew in the listing and previous boxes from the template/pages/category.inc.php file.

But I have certain categories of products where the filters are useful and need to be shown and others where there is no need so that line had to stay.

In the categories where there is no need for filters the resulting output of the sidebar meant that (in desktop view) a void was created on the screen and it was this void that I was trying to remove.

My failing to understand the template meant that I was under the impression that setting the sidebar to display:none would remove the void and that everything would shuffle over and cause the products to display across the page as the category view. Mea culpa.

I did just comment out the sidebar and while this moves the product boxes over to the left we still have a void which I see is caused by <section class="listing categories"...> in the content div.

[img]https://www.buythekilo.co.uk/images/btk1/productweb.png[/img]

So the question now is, can I conditionally remove the void (red) and move the menu (green) over to the left?

I obviously haven't worked on this as I thought that it would be impolite to leave it till I had studied it further, and I do not work that quickly!

But off the top of my head I suspect that I may be looking at having to create a new view and have that appear conditionally?

Thanks for your input.

Dave

Moderator
Şundan Lithuania
Mar 2016 tarihinden beri üye

Either my code is exactly for that or I still not quite understand what you want.

tim
Founder
Şundan Sweden
May 2013 tarihinden beri üye
tim

Simply wrap the sidebar under a condition:

<div id="sidebar">
  ...
</div>
<?php } ?>

Your condition could be some category ids:

<?php if (isset($_GET['category_id']) && in_array($_GET['category_id'], [1, 2, 3])) { ?>

LiteCart Fan
Şundan United Kingdom
Tem 2019 tarihinden beri üye

dodo, Tim

My apologies to both of you.

dodo, your solution does work. I'm working locally to develop the site and either I had a bad cache day or I put the script in the wrong place. But a shut down, restart and walk thro' again and ta-dah we're in business. Mnay thanks.

Tim - many thanks for your assistance. I think in this instance dodo's solution is the better option in that it will automatically do the job without requiring updating. Maybe a consideration to be included in future updates?

Hopefully this may be helpful to somebody else.

I'm not sure how this can be marked solved - but it is.

Thanks

Dave

tim
Founder
Şundan Sweden
May 2013 tarihinden beri üye
tim

LiteCart's application cache obeys the browser cache header.

[hardrefresh]

Bu konu uzun süredir aktif olmadığı için kapatıldı. Konuya mesaj göndermek mümkün değil.
This website uses no cookies and no third party tracking technology. We think we can do better than others and really think about your privacy.