Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added pagination by category #11

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ Or install it yourself as:

$ gem install jekyll-paginate

## Usage

Once the gem is installed on your system, Jekyll will auto-require it. Just set the following configuration

## Optional settings

Paginate only one category (for home page, other use-cases). Add to `_config.yml`:

paginate_category: "blog"

## Contributing

1. Fork it ( http://github.com/jekyll/jekyll-paginate/fork )
Expand Down
9 changes: 7 additions & 2 deletions lib/jekyll-paginate/pagination.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ def generate(site)
# "previous_page" => <Number>,
# "next_page" => <Number> }}
def paginate(site, page)
all_posts = site.site_payload['site']['posts']
if site.config['paginate_category'].nil? || site.config['paginate_category'].empty?
all_posts = site.site_payload['site']['posts']
else
selected_category = site.config['paginate_category']
all_posts = site.site_payload['site']['categories'][selected_category]
end
pages = Pager.calculate_pages(all_posts, site.config['paginate'].to_i)
(1..pages).each do |num_page|
pager = Pager.new(site, num_page, all_posts, pages)
Expand Down Expand Up @@ -82,4 +87,4 @@ def template_page(site)

end
end
end
end