How to Add Collection Tabs to Your Shopify Store
Published on Aug 17, 2024
Are you looking to enhance your Shopify store’s user experience by adding collection tabs? This feature can significantly improve navigation and showcase your products more effectively. In this guide, we’ll walk you through the process of creating collection tabs on your Shopify store, even if you’re new to coding.
Understanding Collection Tabs
What Are Collection Tabs?
Collection tabs are a user interface element that allows customers to easily switch between different product collections on a single page. This feature can help organize your products and make it easier for shoppers to find what they’re looking for.
Benefits of Using Collection Tabs
Implementing collection tabs on your Shopify store can offer several advantages:
- Improved navigation
- Enhanced user experience
- Increased product visibility
- Reduced page load times
Compatibility with Shopify Themes
While collection tabs can be added to most Shopify themes, the implementation process may vary depending on your specific theme. This guide focuses on adding collection tabs to basic Shopify themes, but the principles can be adapted for other themes with some modifications.
Adding Collection Tabs to Your Shopify Store
Step 1: Accessing Your Theme Files
To begin, you’ll need to access your theme’s code:
- Log in to your Shopify admin panel
- Navigate to “Online Store” > “Themes”
- Click on “Actions” > “Edit code” for your current theme
Step 2: Creating a New Section
Next, you’ll create a new section for your collection tabs:
- In the theme editor, click on “Add a new section”
- Name the new section “tabs” and set the file type to “liquid”
- Click “Create section”
Step 3: Adding the Collection Tabs Code
Now, you’ll add the code for your collection tabs. Here’s the most effective solution based on the accepted answer:
{% if section.blocks.size > 0 %}
<div class="tabs-section page-width">
<link rel="stylesheet" href="//code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css">
<script src="//code.jquery.com/jquery-3.6.0.js"></script>
<script src="//code.jquery.com/ui/1.13.2/jquery-ui.js"></script>
{% if section.settings.useslider %}
<script src="//cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.js"></script>
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.css"/>
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick-theme.min.css"/>
{% endif %}
{% if section.settings.title != blank %}
<h2 class="h1">{{ section.settings.title }}</h2>
{% endif %}
<div id="tabs" class="tabs">
{% assign tabContent = '' %}
<ul>
{% for block in section.blocks %}
{% assign collection = collections[block.settings.collection] %}
<li><a href="#tabs-{{ collection.id }}">{{ collection.title }}</a></li>
{% capture content %}
<div id="tabs-{{ collection.id }}">
<ul class="grid product-grid grid--2-col-tablet-down grid--4-col-desktop">
{%- for product in block.settings.collection.products limit: 8 -%}
<li class="grid__item scroll-trigger animate--slide-in">
{% render 'card-product', card_product: product, media_aspect_ratio: section.settings.image_ratio, image_shape: section.settings.image_shape, show_secondary_image: section.settings.show_secondary_image, show_vendor: section.settings.show_vendor, show_rating: section.settings.show_rating, show_quick_add: section.settings.enable_quick_add, section_id: section.id %}
</li>
{%- endfor -%}
</ul>
{% if block.settings.viewall %}
<div class="center collection__view-all scroll-trigger animate--slide-in">
<a class="button" href="{{ block.settings.collection.url }}">
View all
</a>
</div>
{% endif %}
</div>
{% endcapture %}
{% assign tabContent = tabContent | append: content %}
{% endfor %}
</ul>
{{ tabContent }}
</div>
</div>
<script>
$( function() {
{% if section.settings.useslider %}
function tabSlider(){
$('.tabs .product-grid.slick-initialized ').slick('unslick');
$('.tabs .product-grid ').slick({
dots: false,
arrows: true,
infinite: false,
speed: 300,
slidesToShow: 4,
slidesToScroll: 4,
responsive: [
{
breakpoint: 1024,
settings: {
slidesToShow: 3,
slidesToScroll: 3,
infinite: true
}
},
{
breakpoint: 600,
settings: {
slidesToShow: 2,
slidesToScroll: 2
}
},
{
breakpoint: 480,
settings: {
slidesToShow: 1,
slidesToScroll: 1
}
}
]
});
}
{% endif %}
$( "#tabs" ).tabs({
create: function( event, ui ) {
{% if section.settings.useslider %}
tabSlider()
{% endif %}
},
activate: function( event, ui ) {
{% if section.settings.useslider %}
tabSlider()
{% endif %}
}
});
} );
</script>
<style>
.tabs .slick-track .grid__item {
padding: 0 5px;
}
.tabs .slick-next {
right: 0;
}
.tabs .slick-prev {
left: 0;
}
.tabs .slick-next,.tabs .slick-prev {
transform: none;
top: -20px;
}
.tabs .slick-next::before,.tabs .slick-prev::before {
color: #000;
}
.tabs .slick-slider{
margin: 0 -5px;
}
.tabs .collection__view-all a{
color: white!important;
}
.tabs {
background: none!important;
border: none!important
}
.tabs.ui-tabs .ui-tabs-nav {
background: none;
padding: 0;
display: flex;
justify-content: center;
border: none;
}
.tabs-section h2 {
text-align: center;
}
.tabs.ui-tabs .ui-tabs-nav li {
border: none;
background: none;
}
.tabs.ui-tabs .ui-tabs-nav li a{
color: #ddd;
padding: 5px 40px;
border-radius: 50px;
}
.tabs.ui-tabs .ui-tabs-nav li.ui-tabs-active a {
background: grey;
}
</style>
{% endif %}
{% schema %}
{
"name": "Tabs",
"settings": [
{
"type": "text",
"id": "title",
"label": "Title"
},
{
"type": "checkbox",
"id": "useslider",
"label": "Use slider",
"default": true
}
],
"blocks": [
{
"type": "tab",
"name": "Tab",
"limit": 5,
"settings": [
{
"type": "collection",
"id": "collection",
"label": "Collection"
},
{
"type": "checkbox",
"id": "viewall",
"label": "Show view all",
"default": true
}
]
}
],
"presets": [
{
"name": "Tabs",
"blocks": []
}
]
}
{% endschema %}
Step 4: Customizing Your Collection Tabs
After adding the code, you can customize your collection tabs:
- Go to your Shopify admin panel
- Navigate to “Online Store” > “Themes”
- Click on “Customize”
- Add the “Tabs” section to your desired location
- Configure the settings and add your collections
Troubleshooting Common Issues
Images Not Displaying
If you’re experiencing issues with product images not showing up, ensure that:
- Your theme is compatible with the code
- The
card-product
snippet is present in your theme files - Your product images are properly uploaded and linked
Mobile Responsiveness
To improve mobile responsiveness:
- Adjust the CSS for smaller screen sizes
- Consider limiting the number of tabs displayed on mobile
- Test thoroughly on various devices
Adding a “View All” Button
To include a “View All” button for each collection:
- Ensure the
viewall
setting is enabled in the section schema - Customize the button styling in the CSS section
Advanced Customization Options
Changing Tab Styles
To modify the appearance of your tabs:
- Adjust the CSS in the “ section of the code
- Experiment with different colors, fonts, and layouts
Implementing a Slider
If you want to add a slider functionality:
- Enable the
useslider
setting in the section schema - Customize the slider options in the JavaScript code
Adjusting Product Display
To change how products are displayed within tabs:
- Modify the
card-product
snippet or create a custom product card - Adjust the grid layout in the HTML structure
Optimizing Performance
Lazy Loading
Implement lazy loading for images to improve page load times:
- Use Shopify’s built-in lazy loading attributes
- Consider using a JavaScript library for more advanced lazy loading
Minifying Code
Reduce file sizes by minifying your JavaScript and CSS:
- Use online minification tools
- Implement a build process in your development workflow
Caching Strategies
Leverage Shopify’s caching capabilities:
- Use Shopify’s content delivery network (CDN)
- Implement browser caching for static assets
By following this comprehensive guide, you should now be able to create and customize collection tabs on your Shopify store. Remember to test thoroughly and make adjustments as needed to ensure the best possible user experience for your customers.
Take Our Quick Quiz:
Which primary product image do you think has the highest conversion rate?