# Generating Series Navigation

**URL:** <https://discourse.gohugo.io/t/generating-series-navigation/16837>\
**Category:** tips & tricks\
**Created:** [February 5, 2019, 9:59pm UTC](https://discourse.gohugo.io/t/generating-series-navigation/16837 "2019-02-05T21:59:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![angus](https://avatars.discourse-cdn.com/v4/letter/a/b3f665/32.png) [@angus](https://discourse.gohugo.io/u/angus)\
**Post date:** [February 5, 2019, 9:59pm UTC](https://discourse.gohugo.io/t/generating-series-navigation/16837/1 "2019-02-05T21:59:39Z")

</div>

I saw a few people searching for a solution for this, and some things that worked, but seemed overly [complex](http://www.joesacher.com/blog/2017/08/27/converting-series-to-taxonomy/) (like looping through every page to find the ones in a series). So hopefully this is a straightforward solution for most.

Using this assumes you have “series” set up in taxonomy and content marked in front matter with a series name, ie (`series = ["mySeries"]`. It does not require you to put a series in it’s own section, they can be anywhere.

This partial will output:

- “Part x of totalCount”
- an unordered list of links following the pagination class name conventions

as examples. Should be easily adaptable to desired output.

```auto
{{- if .Params.series -}}
  {{- $name := index .Params.series 0 -}}  
	{{- with (index .Site.Taxonomies.series $name) -}}
		{{- $total := .Count -}}
		{{- $startIndex := 0 -}}
		{{- $prevIndex := 0 -}}
		{{- $currIndex := 0 -}}
		{{- $nextIndex := 0 -}}
		{{- $endIndex := ( sub $total 1 ) -}}
		{{- range $index, $page := .Pages.Reverse -}}
			{{- if (eq $page $.Page) -}}	
				{{- $currIndex = $index -}}
				{{- $prevIndex = (sub $index 1) -}}
				{{- $nextIndex = (add $index 1) -}}
  			<p class="series_top_page">Part {{ add $index 1 }} of <a href="{{$.Site.BaseURL}}/series/{{$name | urlize}}">{{ $total }}</a></p>
			{{ end -}}
		{{- end -}}
		{{- /* Example series list following pagination class conventions */ -}}
		<nav role="navigation">
			<ul class="series-pagination pagination">
				<li class="page-item"><a class="page-link" href="{{ (index .Pages.Reverse $startIndex ).RelPermalink }}">First</a>		
				</li><li class="page-item{{ if (lt $prevIndex $startIndex) }} disabled{{ end }}"><a class="page-link" href="{{ (index .Pages.Reverse $prevIndex).RelPermalink }}">Prev</a>
				</li><li class="page-item active"><a class="page-link" href="{{ (index .Pages.Reverse $currIndex).RelPermalink }}">Part {{ add $currIndex 1 }}</a>
				</li><li class="page-item{{ if (gt $nextIndex $endIndex) }} disabled{{ end }}"><a class="page-link" href="{{ (index .Pages.Reverse $nextIndex).RelPermalink }}">Next</a>
				</li><li class="page-item"><a class="page-link" href="{{ (index .Pages.Reverse $endIndex).RelPermalink }}">Last</a>
			</li></ul>
		</nav>
	{{- end -}}
{{- end -}}

```

Note: before someone asks, the `</li>` elements are formatted that way because [whitespace does matter sometimes in HTML](https://medium.com/@patrickbrosset/when-does-white-space-matter-in-html-b90e8a7cdd33).

---

<div class="post-metadata">

**Author:** ![brianwisti](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/brianwisti/32/119_2.png) [@brianwisti](https://discourse.gohugo.io/u/brianwisti)\
**Post date:** [May 12, 2019, 8:21am UTC](https://discourse.gohugo.io/t/generating-series-navigation/16837/2 "2019-05-12T08:21:33Z")

</div>

Thanks you! I was about to decide maybe I didn’t need previous/next series links after all. Used a slightly tweaked version of your solution — and [blogging](https://randomgeekery.org/2019/05/12/turning-taskwarrior-posts-into-a-series/) about what I did, of course.
