Blog Sticky?

Highlighted
New Member
11 0 0
I have read the posts regarding the ability to display blogs in reverse order. What I would like to do is keep my blog in chronoligcal order, but have one entry, kind of like a "welcome to this blog" entry that remains at the top of the page, like a sticky. Any ideas? Thanks so much! Renae www.aluwina.com
0 Likes
Highlighted
Shopify Partner
484 0 3

I haven’t tried this yet, but liquid has a built in sort filter that may work. I know this works in Mephisto, but not sure about Shopify. Give something like this a try:

{% for article in blog.articles sort_by: title %}
Jared Burns, CEO at Getsy (http://get.sy)
0 Likes
Highlighted
Shopify Partner
484 0 3

Oops. I didn’t completely read your question and responded to possibility in sorting your blog entries. In regards to your question about keeping an article at the top, you could do something like this:

{% for article in blog.articles limit: 1 %}
    <h1>{{ article.title }}</h1>
    {{ article.content }}
{% endfor %}

{% paginate blog.articles by 10 %}
    {% for article in blog.articles offset: 1 %}
        <h1>{{ article.title }}</h1>
        {{ article.content }}
    {% endfor %}
    {% if paginate.pages > 1 %}
        {{ paginate | default_pagination }}
    {% endif %}
{% endpaginate %}
Jared Burns, CEO at Getsy (http://get.sy)
0 Likes
Highlighted
Excursionist
699 0 9

I’d do two loops – the first just for the sticky post, and the other for all the rest, by using limit + conditionals:


{% for article in blog.frontpage.articles limit:1 %}
   {% if article.title =="welcome to this blog" %}
    {{article.content}}
   {% endif %}
{% endfor %}

{% for article in blog.frontpage.articles limit:10 %}
   {% if article.title !="welcome to this blog" %}
    {{article.content}}
   {% endif %}
{% endfor %}
operation absurdist feature requests: terminated (http://en.wikipedia.org/wiki/Absurdism)
0 Likes
Highlighted
Excursionist
699 0 9

ha jared – our posts crossed; you beat me to it.

edited: hmm – but with your method you would still get the most recent post first, wouldn’t you?

another possibility would be to just create a different blog, say “stickyblog”, with just that one entry in it and say – i’m just saying without the code now: for article in blogs.stickyblog.articles – article.content – and then the rest as usual in another forloop

operation absurdist feature requests: terminated (http://en.wikipedia.org/wiki/Absurdism)
0 Likes
Highlighted
Shopify Partner
484 0 3

Yeah, no worries. =)

You know, instead of hard coding the article.title into your second loop, you could just offset the loop by one. Well, as long as it’s the first article in the blog.

Jared Burns, CEO at Getsy (http://get.sy)
0 Likes
Highlighted
Excursionist
699 0 9

wooo, criss-crossing!

operation absurdist feature requests: terminated (http://en.wikipedia.org/wiki/Absurdism)
0 Likes
Highlighted
Shopify Partner
484 0 3

Ohh, I think setting an dedicated blog like, “stickiblog” would be the better solution. Good call.

Jared Burns, CEO at Getsy (http://get.sy)
0 Likes
Highlighted
New Member
11 0 0

Can I just say WOW —the shopify community rocks. If I had these questions while I was using ZenCart I would have never received an answer. And I got my answers in less than an hour. I love it. Thanks so much! :)

0 Likes
Highlighted
New Member
3 0 0

Hi Christina,

I'm interesting in apply your code to my blog, but I can't figure out where put it, can u help me?

This is the blog : www.gwumm.com/blogs/news

This is the code of my blog.liquid

<!-- /templates/blog.liquid -->
<style>

header { display:none; }
footer { display:none; }

</style>


{% paginate blog.articles by 5 %}


<div class="grid">

  <div class="grid__item large--five-sixths push--large--one-twelfth">

  
  
    <header class="section-header text-center">
      <h1>
        {% if current_tags %}
          {{ blog.title | link_to: blog.url }} &mdash; {{ current_tags.first }}
        {% else %}
          {{ blog.title }}
        {% endif %}
        <a href="{{ shop.url }}{{ blog.url }}.atom" class="icon-fallback-text rss-link">
          <span class="icon icon-rss" aria-hidden="true"></span>
          <span class="fallback-text">RSS</span>
        </a>
      </h1>
      <hr class="hr--small">
    </header>

    {% for article in blog.articles %}

      {% assign article_content = article.excerpt_or_content %}

      <article class="article grid small--text-center">

        {% unless article.image == blank %}
          <div class="grid__item large--two-eighth">
           
</div>
    
        
 
        
<div class="grid__item large--three-eighths">
   
  
           <a class="article__featured-image-link" href="{{ article.url }}">
              <noscript>
                {{ article.image | img_url: '2048x2048' | img_tag: article.title | escape }}
              </noscript>
              <div class="article__featured-image-wrapper" style="padding-top:{{ 1 | divided_by: article.image.aspect_ratio | times: 100}}%;">
                {% assign img_url = article.image | img_url: '1x1' | replace: '_1x1.', '_{width}x.' %}
                <img class="article__featured-image lazyload"
                  src="{{ article.image | img_url: '300x300' }}"
                  data-src="{{ img_url }}"
                  data-widths="[360, 540, 720, 900, 1080, 1296, 1512, 1728, 2048]"
                  data-aspectratio="{{ article.image.aspect_ratio }}"
                  data-sizes="auto"
                  alt="{{ article.title | escape }}">
              </div>
            </a>
          </div>
        {% endunless %}

        <div class="grid__item large--two-tenths push--large--one-tenth">
          {%comment%}
          <time datetime="{{ article.published_at | date: '%Y-%m-%dT%H:%M:%SZ' }}" class="date">{{ article.published_at | date: format: 'date' }}</time>
          <hr class="hr--small hr--left small--hide">
          {%endcomment%}
        </div>
        <div class="grid__item large--six-tenths push--large--one-tenth">
          <h2 class="h4"><a class="article__heading-link" href="{{ article.url }}">{{ article.title }}</a></h2>
          <div class="rte rte--indented-images">
            {{ article_content | strip_html | truncatewords: 40 }}
          </div>

          <p>
            <a href="{{ article.url }}" class="text-link">{{ 'blogs.article.read_more' | t }} <span class="icon icon-arrow-right" aria-hidden="true"></span></a>
          </p>

          {% if article.tags.size > 0 %}
           {%comment%}
          <ul class="tags tags--article inline-list">
              {% include 'tags-article' %}
            </ul>
          {%endcomment%}
          {% endif %}
        </div>
      </article>

      {% unless forloop.last %}<hr class="hr--clear">{% endunless %}

    {% endfor %}

    {% if paginate.pages > 1 %}
      {% include 'pagination' %}
    {% endif %}

  </div>
</div>

{% endpaginate %}

 

I'd prefer using the code instead create a new blog if possible and I'd like to pick a specific blog post instead the first one. Hope u can help me.

Many thanks

0 Likes