Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7765385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:09:15+00:00 2026-06-01T15:09:15+00:00

I have a custom page for Jekyll: I have a news.markdown file like the

  • 0

I have a custom page for Jekyll: I have a news.markdown file like the following:

{% assign posts_per_page = 5 %}
{% for post in site.categories.ro offset:pagination_skip limit:posts_per_page %}
    ...
    {{ post.content }}
    ...
{% endfor %}
{% include nav.html %}

Where nav.html is in the _includes directory and it looks like this:

{% if pagination_skip %}
  {% capture pagination_skip %}
    {{pagination_skip | plus: posts_per_page}}
  {% endcapture %}
{% else %}
  {% assign pagination_skip = posts_per_page %}
{% endif %}

<div class="next">
  <a rel="prev" href="{{site.basepath}}ro/news/{{ pagination_skip }}">Next</a>
</div>

What I want is for the url .../ro/news/5 to be mapped to the content of news.markdown such that pagination_skip there is 5. Same for 10, 15, whatever. Moreover, .../ro/news/0 should be the same as .../ro/news/ if possible.

Can I do that? How?

I’d like to use as few extensions as possible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:09:17+00:00Added an answer on June 1, 2026 at 3:09 pm

    You try to do it wrong. You want to have a dynamic handling of a URL parameter. Jekyll is a static web generator. So you need to generate all the page that will be visited. You can a generator for that. Please have a look at Generator section on page https://github.com/mojombo/jekyll/wiki/Plugins

    I worked on a generator for what you want to do and it works pretty nicely, I also created the ‘prev’ and ‘next’ button. Please have a look and try it. It works for all categories (not only the ro one), but you can customize it if you want.

    folder structure

     | -- _plugins
        ` news.rb
     | -- _layouts
        ` news.html
     | -- _includes
        ` nav.html
     | -- _config.yml
     | -- ro
        ` -- _posts
          | -- 2012-04-10-test.textile
          | -- 2012-04-10-test2.textile
          | -- 2012-04-10-test4.textile
          | -- 2012-04-10-test6.textile
          | -- 2012-04-10-test15.textile
          | -- 2012-04-10-test3.textile
          ` -- 2012-04-10-test5.textile
      ` _site
    

    the genrator news.rbruby code

    module Jekyll
    
      class NewsPage < Page
        def initialize(site, base, dir, category, posts_number, posts_per_page, pagination_skip)
          @site = site
          @base = base
          @dir = dir
          @name = "news_#{pagination_skip}.html"
    
          self.process(@name)
          self.read_yaml(File.join(base, '_layouts'), 'news.html')
          self.data['category'] = category
          self.data['posts_per_page'] = posts_per_page
          self.data['pagination_skip'] = pagination_skip
          if pagination_skip != 0
            self.data['prev_pagination_skip'] = pagination_skip - posts_per_page
          end
          if pagination_skip + posts_per_page < posts_number
            self.data['next_pagination_skip'] = pagination_skip + posts_per_page
          end
        end
      end
    
      class NewsGenerator < Generator
      safe true
        def generate(site)
          if site.layouts.key? 'news'
            dir = site.config['category_dir'] || 'categories'
            site.categories.keys.each do |category|
              posts_number = site.categories[category].length
              pagination_skip = 0;
              posts_per_page = 5;
              begin
                write_news_page(site, File.join(dir, category), category, posts_number, posts_per_page, pagination_skip)
                pagination_skip += posts_per_page;
              end while pagination_skip < posts_number
            end
          end
        end
    
        def write_news_page(site, dir, category, posts_number, posts_per_page, pagination_skip)
          index = NewsPage.new(site, site.source, dir, category, posts_number, posts_per_page, pagination_skip)
          index.render(site.layouts, site.site_payload)
          index.write(site.dest)
          site.pages << index
        end
      end
    end
    

    The layout of the news.html file

    ---
    ---
    
    {% for post in site.categories[page.category] offset:page.pagination_skip limit:page.posts_per_page %}
      {{ post.content }}
    {% endfor %}
    {% include nav.html %}
    

    The include navigation nav.html

    <div class="nav">
      {% if page.prev_pagination_skip %}
        <a rel="prev" href="{{site.basepath}}categories/{{page.category}}/news_{{page.prev_pagination_skip}}.html">Prev</a>
      {% endif %}
      {% if page.next_pagination_skip %}
        <a rel="next" href="{{site.basepath}}categories/{{page.category}}/news_{{page.next_pagination_skip}}.html">Prev</a>
      {% endif %}
    </div>
    

    Give it a try and let me let me know if you like it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created EXE file using NSIS script.I have created custom page using following
I have created custom posts and I want one page in my site to
I would like to have my own custom change_password page and I am already
I'm trying to return a custom 404 page using IIS6. (I have a site
I have a custom page with the following ListFieldIterator : <SharePoint:ListFieldIterator runat=server ControlMode=Display OnInit=listFieldIterator_Init
We have a custom master page that is deployed to My Site, as well
Live site. I have a custom landing page for the Twenty Eleven Wordpress theme.
I have a module in which I created a custom page with controller and
I have multiple custom controls used on a ASPX (and C#) page registered from
I have a custom search engine on a non-wordpress page. This search engine searches

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.