how to access blog object in different page?

wlminimal
Shopify Partner
10 0 1

Hello!

I want to display 3 most recent blog post in first page(index.html)

so I tried like this

<div class="blog-flexbox">
      {% for article in blog.articles %}
        <div class="blog-tem_flexbox">
          <a href="#" class="blog-image w-inline-block">
            <img src="{{ article.image.src | img_url: 'medium' }}" width="350"
            srcset="{{ article.image.src | img_url: 'medium' }} 500w, {{ article.image.src | img_url: 'medium' }} 562w" sizes="(max-width: 479px) 100vw, (max-width: 767px) 73vw, (max-width: 991px) 63vw, 562px">
          </a>
          <div class="blog-textblock">
            <div class="blog-date">{{ article.created_at }}</div>
            <h1 class="blog-header">{{ article.title }}</h1>
            <p class="blog-text">{{ article.excerpt_or_content }}</p>
            <a href="{{ article.url }}" class="blog-link">Read Article &gt;</a></div>
        </div>
      {% endfor %}
</div>

 

but it shows nothing in index.html but with same code it shows blog post in blog.liquid template

 

How can I show this in other page ?

 

Thanks in advacne

 

Alex_Espinoza
Pathfinder
112 1 40

Hey wlminimal,

Since Shopify lets your store have multiple blogs, you have to target the specific handle of your blog in the liquid code.

You can see that my test store's blog handle is "News" from the screenshot I have attached.

Change the code from:

{% for article in blog.articles %}

to include the handle of your blog:

{% for article in blogs.news.articles %}

That should work. Let me know if you need more help.

The easiest way to get Shopify help. Submit your task, get a quote, and we'll get the work done. Work with me at shupkeep.com
wlminimal
Shopify Partner
10 0 1

Thanks you so much!

0 Likes
Foram
Tourist
4 0 1

But I don't want to use just one blog post, I want all the blogs added to the store in another page. Is it possible to show all blogs on another page?

0 Likes