Jump to content

Make categories a drop down menu

Recommended Posts

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

Add to Home > Settings > Advanced > Code Injection > Header

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.0/jquery.min.js"></script>  
<script>
$(document).ready(function(){
  if (jQuery(window).width() <= 767) {
     $(document).ready(function() {
  var catItem = $('a.category-filter-link');
  var itemTag = $(catItem).html();
  var catDrop = "<select name='Categories' id='categories' class='catDrop'>";
  if (itemTag !== undefined) {
    catItem.each(function(i) {
      var fixLoc = $(this).html().trim().replace(/\s+/g, '+').replace(/&/g, '%26').replace('amp;', '');
      catDrop = catDrop + '<option value=' + fixLoc + '>' + $(this).html() + '</option>';
      i++;
    });
    catDrop = catDrop + "</select>";
    $(catDrop).insertAfter($('.category-filter-wrapper'));
  }
  var urlCat = window.location.href.split("?category=")[1];
  if (urlCat !== undefined) {
    var fixCat = urlCat.replace(/\%27/g, "'")
    $(".catDrop").val(fixCat);
  }
  $(".catDrop").change(function() {
    if ($(this).val() == "All") {
      window.location = "/";
    } else {
      window.location = "?category=" + $(this).val();
    }
  });
});

    }
});
</script>
<style>
@media screen and (max-width:767px) {
nav.category-filter-wrapper {
    display: none;
}
}
</style>

then save & refresh your site.

Code by @rwp

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

How to: Setup Password & Share url Insert Custom CSS - Page Header - Upload Custom Font - Upload File - Find Block ID - Contact Customer Care

Link to comment
  • 4 months later...

 

On 8/24/2020 at 5:00 PM, tuanphan said:

Add to Home > Settings > Advanced > Code Injection > Header



<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.0/jquery.min.js"></script>  
<script>
$(document).ready(function(){
  if (jQuery(window).width() <= 767) {
     $(document).ready(function() {
  var catItem = $('a.category-filter-link');
  var itemTag = $(catItem).html();
  var catDrop = "<select name='Categories' id='categories' class='catDrop'>";
  if (itemTag !== undefined) {
    catItem.each(function(i) {
      var fixLoc = $(this).html().trim().replace(/\s+/g, '+').replace(/&/g, '%26').replace('amp;', '');
      catDrop = catDrop + '<option value=' + fixLoc + '>' + $(this).html() + '</option>';
      i++;
    });
    catDrop = catDrop + "</select>";
    $(catDrop).insertAfter($('.category-filter-wrapper'));
  }
  var urlCat = window.location.href.split("?category=")[1];
  if (urlCat !== undefined) {
    var fixCat = urlCat.replace(/\%27/g, "'")
    $(".catDrop").val(fixCat);
  }
  $(".catDrop").change(function() {
    if ($(this).val() == "All") {
      window.location = "/";
    } else {
      window.location = "?category=" + $(this).val();
    }
  });
});

    }
});
</script>
<style>
@media screen and (max-width:767px) {
nav.category-filter-wrapper {
    display: none;
}
}
</style>

then save & refresh your site.

Code by @rwp

Hey,

Can I get help with this? Should I send an email?

Edited by sharine
Link to comment
On 1/8/2021 at 11:30 PM, sharine said:

 

Hey,

Can I get help with this? Should I send an email?

You can send an email if you want.

Above code doesn't work? 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

How to: Setup Password & Share url Insert Custom CSS - Page Header - Upload Custom Font - Upload File - Find Block ID - Contact Customer Care

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.