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}
<?php
$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')
->all();
$totalentries = count($entries);
if ( ($totalentries / (({segment_2} - 1) * $entriesperpage)) < 1 ) {
$redirect = "TRUE";
} else {
$redirect = "FALSE";
}
$totalpages = ceil($totalentries / $entriesperpage);
?>
{if <?php echo $redirect; ?>}
{redirect='404'}
{/if}
{/if}
{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>
{/exp:channel:entries}
<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>
{/if}
<?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:else}
{if segment_2 != <?php echo $totalpages; ?>}
<a href="{site_url}blog/<?php echo ({segment_2} + 1); ?>" class="page-next">Next</a>
{/if}
{/if}
</div>
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.