Jump to content

[Share] Summary Block Filter by Category

Recommended Posts

Posted

To create a Filter by Category on Summary Block, like this

image.png.2e267d5c2fa64877e96e382f084123aa.png

You can follow these steps.

If it doesn't work, you can share link to page where you use Summary Block + exact code you added, I can check problem easier.

#1. You need to add a Summary Block with Grid or List Layout

image.png.e848de51879251af4fa0b45009832502.png

#2. Next, enable Category on Primary Metadata

image.png.7083e1daa9732da1fa0e4c5e3dd05f3d.png

#3. Use this code to Custom CSS box

/* Summary Filter */
.summary-filter {
	display: none;
}
.summary-filter span {
  display: inline-block;
  margin-left: 5px;
  margin-right: 5px;
  cursor: pointer;
}
.summary-filter {
  text-align: center;
  margin-bottom: 30px;
}
.active-filter {
  text-decoration: underline;
  font-weight: bold;
}
.summary-v2-block .summary-filter {
	display: block !important;
}

image.thumb.png.12a5112d44874ef0496eac17672d9269.png

#4. Use this code to Page Header (page where you use Summary Block)

<div class="summary-filter">
  <span class="filter-all">All</span>
  <span class="filter-inbound-marketing">Inbound Marketing</span>
  <span class="filter-search-engine-marketing">Search Engine Marketing</span>
  <span class="filter-content-marketing">Content Marketing</span>
  <span class="filter-brand-point">Brand Point</span>
</div>

image.png.6c5376267b2edcd6e0c15ee027b150f8.png

In my example, we will create Filter with some links: Inbound Marketing, Search Engine Marketing, Content Marketing, Brand Point

so I added some corresponding ID to <span> tag

  • filter-inbound-marketing
  • filter-search-engine-marketing
  • filter-content-marketing
  • filter-brand-point

If you want to create it with other filters name, you can change both text + ID.

#5. Use this code to Page Header Injection, under #4 code.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
    $('.summary-filter').insertBefore('.summary-item-list');
    const filters = {
        'filter-all': '',
        'filter-inbound-marketing': 'Inbound+marketing',
        'filter-search-engine-marketing': 'Search+Engine+Marketing',
        'filter-content-marketing': 'Content+Marketing',
        'filter-brand-point': 'Brand+Point'
    };
    $('.summary-filter span').click(function() {
        $('.summary-filter span').removeClass('active-filter');
        $(this).addClass('active-filter');
        
        const filterClass = $(this).attr('class').split(' ')[0];
        const keyword = filters[filterClass];
        
        $('.summary-item').hide();
        if (keyword === '') {
            $('.summary-item').show();
        } else {
            $('.summary-item').filter(function() {
                return $(this).find('.summary-metadata-item--cats a[href*="' + keyword + '"]').length > 0;
            }).show();
        }
    });
});
</script>

image.png.28b2d60cb34aa2602f192b19b8707deb.png

You need to change ID in number (1) and Category URL in number (2)

image.png.df9a61c93538b6ccb00f9410abcff61a.png

#6. Number (2), to find these URLs, just click on Category on Summary Block

image.png.f35fc2c99e9eb3472cba7a01fb7cfc9c.png

You will see these

image.png.6db9ddd7cf890bc37c8c40c6af03e545.png

image.png.a8bfeeee5faf1e574b56ff4ef732b62e.png

 

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

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

  • Replies 0
  • Views 365
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Posted Images

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.