CMS Development

dco
Membro | Parceiro Diamante
Membro | Parceiro Diamante

Blog Pagination Showing Page 0

resolver

A client's live Blog allows you to visit www.url.com/blog/page/0 which is generating a lot of broken links. How do I set it so it the lowest page number is 1?

0 Avaliação positiva
1 Solução aceita
JanetArmstrong
Solução
Top colaborador(a) | Parceiro
Top colaborador(a) | Parceiro

Blog Pagination Showing Page 0

resolver

If you have old blog posts with broken links you should fix them or delete. 

 

What does the code for blog listing in your template read?  This is what mine has:

 

 <div class="blog-pagination">
            {% if last_page_num %}
                <a class="previous-posts-link" href="{{ blog_page_link(last_page_num) }}"> << Prev</a>
            {% endif %}
                <a class="hs-button primary all-posts-link" href="{{ group.absolute_url }}/all">All posts</a>
            {% if next_page_num %}
                <a class="next-posts-link" href="{{ blog_page_link(next_page_num) }}">Next >></a>
            {% endif %}
        </div>

Exibir solução no post original

4 Respostas 4
JanetArmstrong
Solução
Top colaborador(a) | Parceiro
Top colaborador(a) | Parceiro

Blog Pagination Showing Page 0

resolver

If you have old blog posts with broken links you should fix them or delete. 

 

What does the code for blog listing in your template read?  This is what mine has:

 

 <div class="blog-pagination">
            {% if last_page_num %}
                <a class="previous-posts-link" href="{{ blog_page_link(last_page_num) }}"> << Prev</a>
            {% endif %}
                <a class="hs-button primary all-posts-link" href="{{ group.absolute_url }}/all">All posts</a>
            {% if next_page_num %}
                <a class="next-posts-link" href="{{ blog_page_link(next_page_num) }}">Next >></a>
            {% endif %}
        </div>
TMukhamedov
Membro

Blog Pagination Showing Page 0

resolver

Not working.  conditional with next_page_num is not registering and displaying that last page's next page is page/0.  Please advice.

0 Avaliação positiva
dco
Membro | Parceiro Diamante
Membro | Parceiro Diamante

Blog Pagination Showing Page 0

resolver

Our code reads as follows:

 

{% set total_pages = contents.total_page_count %} <!-- sets variable for total pages -->
{% set more_pages = total_pages - current_page_num %} <!-- sets variable for how many more pages are past the current pages -->

{% if total_pages > 0 %}
<div class="pagination-main">
<span class="{% if current_page_num == 1 %}disabled{% endif %}"><a href="{% if last_page_num=="1" %}{{ group.absolute_url }}{% else %}{{blog_page_link(last_page_num)}}{% endif %}" class="previous-link"><i class="fa fa-angle-left"></i></a></span>
<ul class="blog-pagination">

{% if more_pages == 1 %}
{% if current_page_num - 4 == 1 %}<li><a href="{{ group.absolute_url }}">{{ current_page_num - 4 }}</a></li>{% endif %}
{% if current_page_num - 4 > 1 %}<li><a href="{{ blog_page_link(current_page_num - 4) }}">{{ current_page_num - 4 }}</a></li>{% endif %}
{% endif %}
{% if more_pages <= 1 %}
{% if current_page_num - 3 == 1 %}<li><a href="{{ group.absolute_url }}">{{ current_page_num - 3 }}</a></li>{% endif %}
{% if current_page_num - 3 > 1 %}<li><a href="{{ blog_page_link(current_page_num - 3) }}">{{ current_page_num - 3 }}</a></li>{% endif %}
{% endif %}
{% if current_page_num - 2 == 1 %}<li><a href="{{ group.absolute_url }}">{{ current_page_num - 2 }}</a></li>{% endif %}
{% if current_page_num - 2 > 1 %}<li><a href="{{ blog_page_link(current_page_num - 2) }}">{{ current_page_num - 2 }}</a></li>{% endif %}
{% if current_page_num - 1 == 1 %}<li><a href="{{ group.absolute_url }}">{{ current_page_num - 1 }}</a></li>{% endif %}
{% if current_page_num - 1 > 1 %}<li><a href="{{ blog_page_link(current_page_num - 1) }}">{{ current_page_num - 1 }}</a></li>{% endif %}
<li class="active"><a href="{% if current_page_num==1 %}{{ group.absolute_url }}{% else %}{{ blog_page_link(current_page_num) }}{% endif %}">{{ current_page_num }}</a></li>
{% if current_page_num + 1 <= total_pages %}<li><a href="{{ blog_page_link(current_page_num + 1) }}">{{ current_page_num + 1 }}</a></li>{% endif %}
{% if current_page_num + 2 <= total_pages %}<li><a href="{{ blog_page_link(current_page_num + 2) }}">{{ current_page_num + 2 }}</a></li>{% endif %}
{% if current_page_num <= 2 %}
{% if current_page_num + 3 <= total_pages %}<li><a href="{{ blog_page_link(current_page_num + 3) }}">{{ current_page_num + 3 }}</a></li>{% endif %}
{% endif %}
{% if current_page_num == 1 %}
{% if current_page_num + 4 <= total_pages %}<li><a href="{{ blog_page_link(current_page_num + 4) }}">{{ current_page_num + 4 }}</a></li>{% endif %}
{% endif %}
</ul>
{% if total_pages >= current_page_num %}
<span class="{% if current_page_num == total_pages %}disabled{% endif %}"><a href="{{blog_page_link(next_page_num)}}" class="next-link"><i class="fa fa-angle-right"></i></a></span>
{% endif %}
</div>
{% endif %}
</div>
</div>

0 Avaliação positiva
JanetArmstrong
Top colaborador(a) | Parceiro
Top colaborador(a) | Parceiro

Blog Pagination Showing Page 0

resolver

You can replace that with what I showed you above.

 

0 Avaliação positiva