Sticky articles: Hide tagged articles and show all other articles in pagination

Hi,

I’ve been trying to work out a solution using liquid to make some articles sticky/show articles tagged with ‘featured’ at the beginning of the blog posts. I’ve managed to get this working and filtered the other articles so that if they don’t have the tag ‘featured’ on them they don’t show. Pagination is set to 6 per page.

But, an issues has arisen.

Using blocks, I have 3 featured articles showing before the rest of the articles, so 3 featured then the first 3 latest articles, and the number of articles changes if less or more featured articles are added. If you then go to the next paginated list of articles, ie news?page=2, the next 3 latest articles are missing and it starts from article number 6!

Also, as I’ve hidden the featured tagged articles from other paginated pages, the number of articles showing doesn’t equal 6 per page.

My blog template code here:


{% comment %}
This template is also used for listing out articles of a specific tag.
You can change layouts or styles by checking if current_tags is true.
{% endcomment %}

  

    {% comment %}

    Loop through a defined number of articles with the 'paginate' tag.
    Don't forget to close the tag after your loop.

  {% endcomment %}
    {% paginate blog.articles by 6 %}
    {%- comment -%}
    

      {% if current_tags %}
      
      # {{ blog.title | link_to: blog.url }} — {{ current_tags.first }}
      {% else %}
      
      # {{ blog.title }} 
      {% endif %}
    

    {%- endcomment -%}
    
   
      {% comment %}
        Loop through each article in your blog. This is limited to what you set for pagination above.
  
        For more info on article liquid tags:
          - http://docs.shopify.com/themes/liquid-variables/article
      {% endcomment %}
  

      {%- if paginate.current_page < 2 and section.settings.showfeatured %}
        {% for block in section.blocks %}
        {%- render 'featured-article', block_settings: block.settings -%}
        

---

        {% assign blocks = 6 | minus: forloop.length %}
        {% endfor %}
        {%- comment -%}
        Use limit:blocks at the end of the article for to limit the first page of results by the featured articles.
        {%- endcomment -%}
        {% for article in blogs[blog.handle].articles limit: blocks   %}
          {% if article.tags contains "featured" %}
            {% continue %}
          {% else %}
            {% render 'blog-article', article: article %}
            {% unless forloop.last %}

---

{% endunless %}            
          {% endif %}
        {% endfor %}
      {%- elsif paginate.current_page >= 2 and section.settings.showfeatured %}
        {% assign blog_articles = blogs[blog.handle].articles %}
        {% for article in blog_articles %}
          {{ forloop.index }}
          {% if article.tags contains "featured" %}
          {% continue %}
          {% else %}
            {% render 'blog-article', article: article %}
            {% unless forloop.last %}

---

{% endunless %}
          {% endif %}
        {% endfor %}  
      {% else %}
      {% for article in blogs[blog.handle].articles %}
      {{ forloop.index }}
            {% render 'blog-article', article: article %}
            {% unless forloop.last %}

---

{% endunless %}          
          {% endfor %}  
      {%- endif -%}

    

    

      {% if section.settings.blog-sidebar-image %}
        {% if section.settings.blog-sidebar-link %}
          
        {% endif %}

        {% capture blog_sidebar_alt %}{{ section.settings.blog-sidebar-image.alt | default: shop.name }}{% endcapture %}
        {% render 'responsive-image' with section.settings.blog-sidebar-image, alt: article.title, class: 'blog-sidebar-image', alt: blog_sidebar_alt | escape %}

        {% if section.settings.blog-sidebar-link %}
          
        {% endif %}
      {% endif %}

      {% if section.settings.show_recent_posts %}
      

        
        {%- if paginate.current_page < 2 and section.settings.showfeatured %}
        
        {% if section.blocks.size > 0 %}
          
Featured Articles

          {% endif %}
          {% for block in section.blocks %}
            {%- assign article = articles[block.settings.article] -%}
              - {{ article.title }}
                

                  {% if section.settings.blog_show_date %}
                
                  {% endif %}
              

          {% endfor %}
            
          {{ 'blogs.sidebar.recent_articles' | t }}

            {% for article in blogs[blog.handle].articles limit: blocks %}
              - {{ article.title }}
                

                  {% if section.settings.blog_show_date %}
                  
                  {% endif %}
              

            {% endfor %}
        {% elsif paginate.current_page >= 2 and section.settings.showfeatured %}
          {{ 'blogs.sidebar.recent_articles' | t }}

          
          {% for article in blogs[blog.handle].articles %}
          {% if article.tags contains "featured" %}
          {% continue %}
          {% else %}
                - {{ article.title }}
                  

                    {% if section.settings.blog_show_date %}
                    
                    {% endif %}
                

                {% endif %}
            {% endfor %}
        {% else %}
          {{ 'blogs.sidebar.recent_articles' | t }}

          {% for article in blogs[blog.handle].articles %}
              - {{ article.title }}
                

                  {% if section.settings.blog_show_date %}
                  
                  {% endif %}
              
          {% endfor %}
        {% endif %}
      

      {% endif %}

      {% if section.settings.show_blog_tags %}
        {{ 'blogs.sidebar.categories' | t }}

        
          {% for tag in blog.all_tags %}
            {% if current_tags contains tag %}
            - {{ tag }}

            {% else %}
            - {{ tag | link_to_tag: tag }}
            {% endif %}
          {% endfor %}
        

      {% endif %}

    

    
        {% if paginate.pages > 1 %}
        

          

            {% if paginate.previous %}
              - 

            {% else %}
              - «

            {% endif %}

            {% for part in paginate.parts %}
              {% if part.is_link %}
                - {{ part.title | link_to: part.url }}

              {% else %}
                {% if part.title == '…' %}
                - {{ part.title }}

                {% else %}
                - {{ part.title | link_to: part.url }}

                {% endif %}
              {% endif %}
            {% endfor %}

            {% if paginate.next %}
              - 

            {% else %}
              - »
            {% endif %}
          

        

      {% endif %}

    

    {% endpaginate %}
  

{% schema %}
{
    "name": {
        "en": "Blog pages",
        "de": "Blogseiten",
        "es": "Páginas del blog",
        "fr": "Pages du blog",
        "pt-PT": "Páginas de blogs"
    },
    "settings": [
        {
            "type": "checkbox",
            "id": "show_author_name",
            "label": {
                "en": "Show author name",
                "de": "Autorennamen anzeigen",
                "es": "Mostrar el nombre de autor",
                "fr": "Afficher le nom de l'auteur",
                "pt-PT": "Mostrar nome do autor"
            },
            "default": true
        },
        {
            "type": "checkbox",
            "id": "showfeatured",
            "label":"Show featured articles as sticky posts",
            "default": true
        },
        {
            "type": "header",
            "content": {
                "en": "Sidebar",
                "de": "Seitenleiste",
                "es": "Barra lateral",
                "fr": "Barre latérale",
                "pt-PT": "Barra lateral"
            }
        },
        {
            "type": "image_picker",
            "id": "blog-sidebar-image",
            "label": {
                "en": "Image",
                "de": "Bild",
                "es": "Imagen",
                "fr": "Image",
                "pt-PT": "Imagem"
            }
        },
        {
            "type": "url",
            "id": "blog-sidebar-link",
            "label": {
                "en": "Link",
                "de": "Link",
                "es": "Enlace",
                "fr": "Lien",
                "pt-PT": "Ligação"
            }
        },
        {
            "type": "checkbox",
            "id": "show_blog_tags",
            "label": {
                "en": "Show tags",
                "de": "Tags anzeigen",
                "es": "Mostrar etiquetas",
                "fr": "Afficher les étiquettes",
                "pt-PT": "Mostrar etiquetas"
            },
            "default": false
        },
        {
            "type": "checkbox",
            "id": "show_recent_posts",
            "label": {
                "en": "Show 'Recent articles'",
                "de": "Neueste Artikel' anzeigen",
                "es": "Mostrar 'Artículos recientes'",
                "fr": "Afficher 'Articles récents'",
                "pt-PT": "Mostrar \"artigos recentes\""
            },
            "default": true
        },
        {
            "type": "checkbox",
            "id": "blog_show_date",
            "label": {
                "en": "Show dates",
                "de": "Daten anzeigen",
                "es": "Mostrar fechas",
                "fr": "Afficher les dates",
                "pt-PT": "Mostrar datas"
            },
            "default": true
        }
    ],
    "blocks": [
        {
            "type": "featured",
            "name": "Featured Articles",
            "settings": [                                     
                {
                    "type": "article",
                    "id": "article",
                    "label": "Article"
                }
            ]
        }
    ]
}
{% endschema %}

Anyone able to help fix this issue so the correct number of articles are showing from page 2?

Thanks