Change the blog to 3 - 4 grid column
In main-blog.liquid, change the entire code to the followings:
- <script
- src="{{ 'blog-posts-list.js' | asset_url }}"
- type="module"
- fetchpriority="low"
- ></script>
- {% liquid
- if section.settings.background_color != blank
- render 'contrast-override', background_color: section.settings.background_color, section_id: section.id
- endif
- %}
- <blog-posts-list section-id="{{ section.id }}">
- <div
- class="section-background{% if section.settings.background_color != blank %} color-custom-{{ section.id }}{% endif %}"
- ></div>
- <div
- class="
- section
- {% if section.settings.background_color != blank %}color-custom-{{ section.id }}{% endif %}
- blog-posts
- spacing-style
- size-style
- "
- data-testid="blog-posts"
- style="{% render 'spacing-style', settings: section.settings %}"
- >
- {% content_for 'blocks' %}
- <div
- ref="grid"
- class="blog-posts-container"
- style="--desktop-columns: {{ section.settings.columns }};"
- >
- {% liquid
- assign image_index = 0
- # The first two images reach the initial mobile viewport; later images use native lazy-loading.
- assign eager_image_count = 2
- # These sizes mirror --narrow-page-width in theme-styles-variables.liquid,
- # --page-margin in base.css, and --columns-gap below.
- # Desktop content uses a 40px page margin on each side, with 36px column gaps.
- # Desktop: 3 or 4 columns (setting). Tablet (750px-1023px): 3 columns. Mobile: 1 column.
- if section.settings.columns == '4'
- assign image_sizes = '(min-width: 1520px) 333px, (min-width: 1024px) calc(25vw - 47px), (min-width: 750px) calc(33.33vw - 51px), calc(100vw - 32px)'
- else
- assign image_sizes = '(min-width: 1520px) 456px, (min-width: 750px) calc(33.33vw - 51px), calc(100vw - 32px)'
- endif
- %}
- {% for article in blog.articles %}
- {% liquid
- assign scale = 0.6
- assign is_horizontal = false
- assign image_loading = 'lazy'
- assign image_fetch_priority = 'auto'
- if article.image
- assign image_index = image_index | plus: 1
- if image_index <= eager_image_count
- assign image_loading = 'eager'
- endif
- if image_index == 1
- assign image_fetch_priority = 'high'
- endif
- endif
- %}
- {% # Keep the mobile breakpoint in the style block below in sync with the responsive image sizes above. %}
- {% style %}
- [data-blog-index="{{ section.id }}-{{ forloop.index }}"] {
- --blog-post-card-scale: {{ scale }};
- }
- @media screen and (max-width: 749px) {
- [data-blog-index="{{ section.id }}-{{ forloop.index }}"] {
- --blog-post-card-scale: 0.5;
- }
- }
- {% endstyle %}
- <div
- class="blog-post-item"
- data-testid="blog-post-item"
- data-blog-index="{{ section.id }}-{{ forloop.index }}"
- >
- {% content_for 'block',
- id: 'static-blog-post-card',
- type: '_blog-post-card',
- article: article,
- image_sizes: image_sizes,
- image_loading: image_loading,
- image_fetch_priority: image_fetch_priority,
- is_horizontal: is_horizontal
- %}
- </div>
- {% endfor %}
- </div>
- </div>
- </blog-posts-list>
- {% stylesheet %}
- /**
- * Blog posts page layout
- */
- .blog-posts {
- --page-content-width: var(--narrow-page-width);
- --page-width: calc(var(--page-content-width) + (var(--page-margin) * 2));
- /* Keep the responsive image sizes above in sync with this gap. */
- --columns-gap: 36px;
- --rows-gap: 36px;
- }
- /**
- * Grid: 3 or 4 columns on desktop (section setting), 3 on tablet, 1 on mobile.
- */
- .blog-posts-container {
- display: grid;
- grid-template-columns: repeat(var(--desktop-columns, 3), 1fr);
- gap: 1rem;
- width: 100%;
- column-gap: var(--columns-gap);
- row-gap: var(--rows-gap);
- }
- /* Tablet: always 3 columns */
- @media screen and (max-width: 1023px) {
- .blog-posts-container {
- grid-template-columns: repeat(3, 1fr);
- }
- }
- /* Mobile: 1 column */
- @media screen and (max-width: 749px) {
- .blog-posts-container {
- grid-template-columns: 1fr;
- }
- }
- .blog-post-item {
- grid-column: auto;
- background-color: var(--color-background);
- }
- /**
- * When there's no image, the blog post item has a border.
- */
- .blog-post-item {
- border: 1px solid rgb(var(--color-foreground-rgb) / var(--opacity-20));
- padding: 0 1rem 1rem;
- }
- .blog-post-item:has(.blog-post-card__image-container) {
- border: none;
- padding: 0;
- }
- /**
- * Square featured images at every screen size.
- */
- .blog-post-item .blog-post-card__image-container {
- aspect-ratio: 1 / 1 !important;
- overflow: hidden;
- }
- .blog-post-item .blog-post-card__image-container img {
- width: 100%;
- height: 100% !important;
- aspect-ratio: 1 / 1 !important;
- object-fit: cover;
- }
- {% endstylesheet %}
- {% schema %}
- {
- "name": "t:names.blog_posts",
- "blocks": [
- {
- "type": "@theme"
- },
- {
- "type": "@app"
- },
- {
- "type": "text"
- },
- {
- "type": "icon"
- },
- {
- "type": "image"
- },
- {
- "type": "button"
- },
- {
- "type": "video"
- },
- {
- "type": "group"
- },
- {
- "type": "spacer"
- },
- {
- "type": "_divider"
- }
- ],
- "disabled_on": {
- "groups": ["header"]
- },
- "settings": [
- {
- "type": "select",
- "id": "columns",
- "label": "Columns (desktop)",
- "options": [
- { "value": "3", "label": "3 columns" },
- { "value": "4", "label": "4 columns" }
- ],
- "default": "3"
- },
- {
- "type": "color",
- "id": "background_color",
- "label": "t:settings.background_color",
- "placeholder": "t:settings.default"
- },
- {
- "type": "header",
- "content": "t:content.padding"
- },
- {
- "type": "range",
- "id": "padding-block-start",
- "label": "t:settings.top",
- "min": 0,
- "max": 100,
- "step": 1,
- "unit": "px",
- "default": 0
- },
- {
- "type": "range",
- "id": "padding-block-end",
- "label": "t:settings.bottom",
- "min": 0,
- "max": 100,
- "step": 1,
- "unit": "px",
- "default": 0
- }
- ]
- }
- {% endschema %}