Adding Prev/Next functionality to all lists of pages (sections, taxonomies, etc)

This commit is contained in:
spf13
2014-11-27 23:08:06 -05:00
parent 78316903a2
commit b719ba7e2b
3 changed files with 158 additions and 0 deletions

View File

@@ -160,6 +160,30 @@ func (wp WeightedPages) Pages() Pages {
return pages
}
func (wp WeightedPages) Prev(cur *Page) *Page {
for x, c := range wp {
if c.Page.UniqueId() == cur.UniqueId() {
if x == 0 {
return wp[len(wp)-1].Page
}
return wp[x-1].Page
}
}
return nil
}
func (wp WeightedPages) Next(cur *Page) *Page {
for x, c := range wp {
if c.Page.UniqueId() == cur.UniqueId() {
if x < len(wp)-1 {
return wp[x+1].Page
}
return wp[0].Page
}
}
return nil
}
func (p WeightedPages) Len() int { return len(p) }
func (p WeightedPages) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
func (p WeightedPages) Sort() { sort.Stable(p) }