Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

123
Visualizações
How do I load a Shopify blog view/template on a tag even if there are no articles for that tag?

Expected Result:

As the title says, I'm trying to get the custom hero section of my template to load, even when they are no articles for a tag.

Actual Result:

The behavior right now is intermittent. Some tags will load the hero but most won't.

Errors:

In the console on the ones that don't work I receive a 'GET 404' error and my 404 page loads. On the ones that are working I'm not getting any error.

The HTML:

<div id="blog-hero">
    <!-- blog hero goes here -->
</div>

<div id="article-index-background">
    <div id="article-section" class="width g-flex">
        <!-- paginate articles here -->
    </div>
</div>

The JS:

// get the hero
const pathName = window.location.pathname;
let blog_div = document.getElementById('blog-hero');
let blogName = pathName.split('/')[2];
let tagName = pathName.split('/')[4];

let request = new XMLHttpRequest();
request.open('GET', `/?section_id=blog--hero-${blogName}-blog--${tagName}`)

request.onload = () => {
    if(request.readyState === request.DONE) {
        if (request.status === 200) {
             blog_div.innerHTML = request.responseText;
         }
    }
};

request.send(null);

// load the articles, paginate on screen width
let screenWidth = window.innerWidth;
let articleSection = document.getElementById('article-section');

if (screenWidth < 600) {
    articleSection.innerHTML = `
    {% if blog.articles %}
        {% paginate blog.articles by 3 %}
            {% for article in blog.articles %}
                // some html
            {% endfor %}
        {% endpaginate %}
    {% endif %}
    `

} else if (screenWidth >= 600) {
    articleSection.innerHTML = `
    {% if blog.articles %}
        {% paginate blog.articles by 6 %}
            {% for article in blog.articles %}
                // some html
            {% endfor %}
        {% endpaginate %}
    {% endif %}
    `

}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

A simply workaround I implemented to solve this was to make a post on the blog with the title "Hidden Post" and hide any blog article with that title on the frontend. Kinda hacky, but it works.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda