github.com/rabbouni145/gg@v0.47.1/docs/content/en/templates/pagination.md (about) 1 --- 2 title: Pagination 3 linktitle: Pagination 4 description: Hugo supports pagination for your homepage, section pages, and taxonomies. 5 date: 2017-02-01 6 publishdate: 2017-02-01 7 lastmod: 2017-02-01 8 categories: [templates] 9 keywords: [lists,sections,pagination] 10 menu: 11 docs: 12 parent: "templates" 13 weight: 140 14 weight: 140 15 sections_weight: 140 16 draft: false 17 aliases: [/extras/pagination,/doc/pagination/] 18 toc: true 19 --- 20 21 The real power of Hugo pagination shines when combined with the [`where` function][where] and its SQL-like operators: [`first`][], [`last`][], and [`after`][]. You can even [order the content][lists] the way you've become used to with Hugo. 22 23 ## Configure Pagination 24 25 Pagination can be configured in your [site configuration][configuration]: 26 27 `Paginate` 28 : default = `10`. This setting can be overridden within the template. 29 30 `PaginatePath` 31 : default = `page`. Allows you to set a different path for your pagination pages. 32 33 Setting `Paginate` to a positive value will split the list pages for the homepage, sections and taxonomies into chunks of that size. But note that the generation of the pagination pages for sections, taxonomies and homepage is *lazy* --- the pages will not be created if not referenced by a `.Paginator` (see below). 34 35 `PaginatePath` is used to adapt the `URL` to the pages in the paginator (the default setting will produce URLs on the form `/page/1/`. 36 37 ## List Paginator Pages 38 39 {{% warning %}} 40 `.Paginator` is provided to help you build a pager menu. This feature is currently only supported on homepage and list pages (i.e., taxonomies and section lists). 41 {{% /warning %}} 42 43 There are two ways to configure and use a `.Paginator`: 44 45 1. The simplest way is just to call `.Paginator.Pages` from a template. It will contain the pages for *that page*. 46 2. Select a subset of the pages with the available template functions and ordering options, and pass the slice to `.Paginate`, e.g. `{{ range (.Paginate ( first 50 .Pages.ByTitle )).Pages }}`. 47 48 For a given **Page**, it's one of the options above. The `.Paginator` is static and cannot change once created. 49 50 The global page size setting (`Paginate`) can be overridden by providing a positive integer as the last argument. The examples below will give five items per page: 51 52 * `{{ range (.Paginator 5).Pages }}` 53 * `{{ $paginator := .Paginate (where .Pages "Type" "post") 5 }}` 54 55 It is also possible to use the `GroupBy` functions in combination with pagination: 56 57 ``` 58 {{ range (.Paginate (.Pages.GroupByDate "2006")).PageGroups }} 59 ``` 60 61 ## Build the navigation 62 63 The `.Paginator` contains enough information to build a paginator interface. 64 65 The easiest way to add this to your pages is to include the built-in template (with `Bootstrap`-compatible styles): 66 67 ``` 68 {{ template "_internal/pagination.html" . }} 69 ``` 70 71 {{% note "When to Create `.Paginator`" %}} 72 If you use any filters or ordering functions to create your `.Paginator` *and* you want the navigation buttons to be shown before the page listing, you must create the `.Paginator` before it's used. 73 {{% /note %}} 74 75 The following example shows how to create `.Paginator` before its used: 76 77 ``` 78 {{ $paginator := .Paginate (where .Pages "Type" "post") }} 79 {{ template "_internal/pagination.html" . }} 80 {{ range $paginator.Pages }} 81 {{ .Title }} 82 {{ end }} 83 ``` 84 85 Without the `where` filter, the above example is even simpler: 86 87 ``` 88 {{ template "_internal/pagination.html" . }} 89 {{ range .Paginator.Pages }} 90 {{ .Title }} 91 {{ end }} 92 ``` 93 94 If you want to build custom navigation, you can do so using the `.Paginator` object, which includes the following properties: 95 96 `PageNumber` 97 : The current page's number in the pager sequence 98 99 `URL` 100 : The relative URL to the current pager 101 102 `Pages` 103 : The pages in the current pager 104 105 `NumberOfElements` 106 : The number of elements on this page 107 108 `HasPrev` 109 : Whether there are page(s) before the current 110 111 `Prev` 112 : The pager for the previous page 113 114 `HasNext` 115 : Whether there are page(s) after the current 116 117 `Next` 118 : The pager for the next page 119 120 `First` 121 : The pager for the first page 122 123 `Last` 124 : The pager for the last page 125 126 `Pagers` 127 : A list of pagers that can be used to build a pagination menu 128 129 `PageSize` 130 : Size of each pager 131 132 `TotalPages` 133 : The number of pages in the paginator 134 135 `TotalNumberOfElements` 136 : The number of elements on all pages in this paginator 137 138 ## Additional information 139 140 The pages are built on the following form (`BLANK` means no value): 141 142 ``` 143 [SECTION/TAXONOMY/BLANK]/index.html 144 [SECTION/TAXONOMY/BLANK]/page/1/index.html => redirect to [SECTION/TAXONOMY/BLANK]/index.html 145 [SECTION/TAXONOMY/BLANK]/page/2/index.html 146 .... 147 ``` 148 149 150 [`first`]: /functions/first/ 151 [`last`]: /functions/last/ 152 [`after`]: /functions/after/ 153 [configuration]: /getting-started/configuration/ 154 [lists]: /templates/lists/ 155 [where]: /functions/where/