Search code examples
expressionengine

Navigation and pagination issues in ExpressionEngine


I’ve set up a site with eight channels divided into two sections.

One of the sections is called “Articles” and within that section there are two channels, “Features” and “News”.

Everything was working great until I introduced pagination into the equation.

On the Articles index page, I have tabs for “Latest”, “Features” and “News” and I navigate through them and select entries based on the segment:

<ul id="tabs">
<li>{if segment_2 == ''}<strong>Latest</strong>{if:else}<a href="{site_url}articles/">Latest</a>{/if}</li>
<li>{if segment_2 == 'features'}<strong>Features</strong>{if:else}<a href="{path=articles/features}">Features</a>{/if}</li>                    
<li>{if segment_2 == 'news'}<strong>News</strong>{if:else}<a href="{path=articles/news}">News</a>{/if}</li>
</ul>
{if segment_2 == ''}{exp:channel:entries channel="features|news" limit="10" dynamic="no" order="date" paginate="both"}{/if}
{if segment_2 == 'features'}{exp:channel:entries channel="features" limit="10" dynamic="no" order="date" paginate="both"}{/if}                
{if segment_2 == 'news'}{exp:channel:entries channel="news" limit="10" dynamic="no" order="date" paginate="both"}{/if}  

site.com/articles brings up all entries
site.com/articles/features/ brings up all entries in the Features channel
site.com/articles/news/ brings up all entries in the News channel

This works great until there is a channel with multiple pages and something like “P4” is added to the URL and then {segment_2} for the unfiltered index becomes P4 instead of what I am doing to navigate the channel entries.

Paginate URL: site.com/articles/P4

I guess my question is this:

Am I navigating or filtering entries correctly? If so how would I do so now with pagination?

Thanks!


Solution

  • There are two possible solutions here.

    You can use the paginate_base parameter to explicitly tell EE to use a specific path before the pagination argument:

    {if segment_2 == 'features'}{exp:channel:entries channel="features" limit="10" dynamic="no" order="date" paginate="both" paginate_base="articles/features"}{/if}                
    {if segment_2 == 'news'}{exp:channel:entries channel="news" limit="10" dynamic="no" order="date" paginate="both" paginate_base="articles/news"}{/if}`
    

    Alternately - and my preferred solution - is to create two new templates under the "articles" group, named "news" and "features", and list your entries there. You can avoid any duplication of code by turning your tab navigation (and even the markup/logic you plan on placing between your channel:entries tags, if it will be the same for each section) into snippets.