I want my URLs to be like the following: domain.com/blog/2

Currently they are: domain.com/blog/P6

RIght now if I show 6 articles per page, my pagination will jump by 6.

For instance, Page 1 will be /, page 2 will be /P6/, page 3 will be /P9/, ect.

  • 2
    I guess this is not possible in current EE pagination system Feb 14, 2018 at 9:41
  • So the most common and practical URL structure isn't possible with EE? That's insane. There has to be a way to achieve it. Who the hell has P3, P6, P9, ect for their URLs? What were they thinking? Feb 14, 2018 at 14:56
  • They thinking to set offset in URL so they can easily get next batch of data. So P10 id pagination where P stands for pagination and 10 is an Offset. Feb 15, 2018 at 8:43
  • Yes I understand it's an offset. I'm saying it's stupid to have URLs like that. Feb 15, 2018 at 13:55

1 Answer 1


I was able to accomplish this by doing the following:

  • On index template, set Allow PHP? to Yes
  • On index template, set PHP Parsing Stage to Input
  • On single template, set Template route override to /blog/{url_title:regex[(((?!(\d+|category\/)).)+?)]} (make sure to swap blog for your index page url)

Inside index template, use the following:

<?php $entriesperpage = 6; ?>
      {if segment_2}
        $entries = ee('Model')->get('ChannelEntry')
         ->filter('channel_id', 4) // or whatever you want/need to filter on
         ->filter('status', 'IN', array('open', 'other_status'))
         ->order('title', 'ASC')
         $totalentries = count($entries);
         if ( ($totalentries / (({segment_2} - 1) * $entriesperpage)) < 1 ) {
           $redirect = "TRUE";
         } else {
           $redirect = "FALSE";
         $totalpages = ceil($totalentries / $entriesperpage);
         {if <?php echo $redirect; ?>}
      {exp:channel:entries channel="articles" dynamic="no" {if segment_2} offset="<?php echo ({segment_2} - 1) * $entriesperpage; ?>" {/if} limit="<?php echo $entriesperpage; ?>" paginate="bottom"}
        <a class="post" href="{route='blog/single' url_title='{url_title}'}"></a>
      <div class="pagination">
        {if segment_2}
          <?php $prevpage = {segment_2}-1; ?>
          <a href="{site_url}blog<?php if ($prevpage != 1) { echo '/' . $prevpage; } ?>" class="page-prev">Prev</a>
        <?php for ($i = 1; $i <= $totalpages; $i++) { ?>
          <a href="{site_url}blog<?php if ($i != 1) { echo '/' . $i; } ?>" class="{if (!segment_2 && (<?php echo $i; ?> == 1)) || (segment_2 == <?php echo $i; ?>)} active{/if}"><?php echo $i; ?></a>
        <?php } ?>
        {if !segment_2}
          <a href="{site_url}blog/2" class="page-next">Next</a>
          {if segment_2 != <?php echo $totalpages; ?>}
          <a href="{site_url}blog/<?php echo ({segment_2} + 1); ?>" class="page-next">Next</a>

This will produce the following urls:

  • website.com/blog
  • website.com/blog/2
  • website.com/blog/3
  • etc

Make sure to set $entriesperpage to your desired entries per page, channel_id to the correlating ID of channel you're displaying, and update blog to your index page url.

We are essentially using our own pagination logic, and I'm sure this could be cleaned up a bit.

Note that this will display all page links, so you may want to add custom logic if dealing with many pages.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.