Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit790781b

Browse files
committed
Truncate pagination links with [...] to avoid long lists
1 parentdfaf869 commit790781b

File tree

2 files changed

+67
-34
lines changed

2 files changed

+67
-34
lines changed

‎_includes/pagination.html‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{% if paginator.total_pages> 1 %}
2+
<divclass="pagination">
3+
<ulclass="inline-list">
4+
{% comment %} Link for previous page {% endcomment %}
5+
{% if paginator.previous_page %}
6+
{% if paginator.previous_page == 1 %}
7+
<li><ahref="{{ site.url }}"class="btn">Previous</a></li>
8+
{% else %}
9+
<li><ahref="{{ site.url }}/page{{ paginator.previous_page }}/"class="btn">Previous</a></li>
10+
{% endif %}
11+
{% endif %}
12+
13+
{% comment %} First page {% endcomment %}
14+
{% if paginator.page == 1 %}
15+
<li><strongclass="current-page">1</strong></li>
16+
{% else %}
17+
<li><ahref="{{ site.url }}">1</a></li>
18+
{% endif %}
19+
20+
{% assign page_start = 2 %}
21+
{% if paginator.page> 4 %}
22+
{% assign page_start = paginator.page | minus: 2 %}
23+
{% comment %} Ellipsis for truncated links {% endcomment %}
24+
<li></li>
25+
{% endif %}
26+
27+
{% assign page_end = paginator.total_pages | minus: 1 %}
28+
{% assign pages_to_end = paginator.total_pages | minus: paginator.page %}
29+
{% if pages_to_end> 4 %}
30+
{% assign page_end = paginator.page | plus: 2 %}
31+
{% endif %}
32+
33+
{% for index in (page_start..page_end) %}
34+
{% if index == paginator.page %}
35+
<li><strongclass="current-page">{{index}}</strong></li>
36+
{% else %}
37+
{% comment %} Distance from current page and this link {% endcomment %}
38+
{% assign dist = paginator.page | minus: index %}
39+
{% if dist<0%}
40+
{%comment%}Distancemustbeapositivevalue{%endcomment%}
41+
{%assigndist =0|minus:dist%}
42+
{%endif%}
43+
<li><ahref="{{ site.url }}/page{{ index }}/">{{index}}</a></li>
44+
{% endif %}
45+
{% endfor %}
46+
47+
{% comment %} Ellipsis for truncated links {% endcomment %}
48+
{% if pages_to_end> 3 %}
49+
<li></li>
50+
{% endif %}
51+
52+
{% if paginator.page == paginator.total_pages %}
53+
<li><strongclass="current-page">{{ paginator.page }}</strong></li>
54+
{% else %}
55+
<li><ahref="{{ site.url }}/page{{ paginator.total_pages }}/">{{ paginator.total_pages }}</a></li>
56+
{% endif %}
57+
58+
{% comment %}
59+
Link next page
60+
{% endcomment %}
61+
{% if paginator.next_page %}
62+
<li><ahref="{{ site.url }}/page{{ paginator.next_page }}/"class="btn">Next</a></li>
63+
{% endif %}
64+
</ul>
65+
</div>
66+
{% endif %}

‎index.html‎

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -39,37 +39,4 @@ <h1 class="entry-title"><a href="{{ site.url }}{{ post.url }}" rel="bookmark" ti
3939
</article><!-- /.hentry -->
4040
{% endfor %}
4141

42-
<divclass="pagination">
43-
{% if paginator.previous_page %}
44-
{% if paginator.previous_page == 1 %}
45-
<ahref="{{ site.url }}"class="btn">Previous</a>
46-
{% else %}
47-
<ahref="{{ site.url }}/page{{ paginator.previous_page }}"class="btn">Previous</a>
48-
{% endif %}
49-
{% else %}
50-
Previous
51-
{% endif %}
52-
<ulclass="inline-list">
53-
<li>
54-
{% if paginator.page == 1 %}
55-
<spanclass="current-page">1</span>
56-
{% else %}
57-
<ahref="{{ site.url }}">1</a>
58-
{% endif %}
59-
</li>
60-
{% for count in (2..paginator.total_pages) %}
61-
<li>
62-
{% if count == paginator.page %}
63-
<spanclass="current-page">{{ count }}</span>
64-
{% else %}
65-
<ahref="{{ site.url }}/page{{ count }}">{{ count }}</a>
66-
{% endif %}
67-
</li>
68-
{% endfor %}
69-
</ul>
70-
{% if paginator.next_page %}
71-
<ahref="{{ site.url }}/page{{ paginator.next_page }}"class="btn">Next</a>
72-
{% else %}
73-
Next
74-
{% endif %}
75-
</div><!-- /.pagination -->
42+
{% include pagination.html %}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp