I’ve got an issue with EE2.x’s built-in pagination. I’m using EE 2.1.3.
I’m using the Previous and Next style of pagination on one of my blogs. My template code looks something like this:
<h1>News</h1>
<ul>
{exp:channel:entries limit="4" paginate="bottom" channel="news"}
<li class="{switch='left|right'}"><article>...</article></li>
{paginate}
{if {total_pages} > 1}
</ul><div class="clear"></div><ul>
{/if}
{if next_page}
<li class="pagination pagination_left"><a href="http://{auto_path}">OLDER POSTS</a></li>
{/if}
{if previous_page}
<li class="pagination pagination_right"><a href="http://{auto_path}">NEWER POSTS</a></li>
{/if}
{/paginate}
{/exp:channel:entries}
</ul>The problem with the above code is that on the last page of posts, the NEWER POSTS link shows up in the left column instead of the right column. On every other page where it is displayed, it shows up in the right column (with the OLDER POSTS link in the left column).
The only way I can get it to show up in the right column when it is the only pagination link on the page (without some fancy CSS) is by outputting an empty <li class=“pagination pagination_left”></li> first before the pagination link LI.
When I try adding an {if} block inside the {if previous_page} block, EE appears to have trouble interpreting the {if} block. I’ll give a few examples of what I’m talking about.
For example, if I modify the {if previous_page} block like this:
{if previous_page}
{if !next_page}<li class="pagination pagination_left"></li>{/if}
<li class="pagination pagination_right"><a href="http://{auto_path}">NEWER POSTS</a></li>
{/if}Then on the first page of posts I get this error:
Parse error: syntax error, unexpected T_ENDIF in /[...]/system/expressionengine/libraries/Functions.php(650) : eval()‘d code on line 87
And on every pagintion page (/P4, /P8, etc), the {if previous_page} block outputs nothing.
Another example, if I modify the {if previous_page} block like this:
{if previous_page}
{if {current_page} == {total_pages}}<li class="pagination pagination_left"></li>{/if}
<li class="pagination pagination_right"><a href="http://{auto_path}">NEWER POSTS</a></li>
{/if}Then on the first page of posts I get this error:
Parse error: syntax error, unexpected T_ENDIF in /[...]/system/expressionengine/libraries/Functions.php(650) : eval()‘d code on line 87
And on every pagination page (/P4, /P8, etc), with the exception of the last page, the {if previous_page} block outputs nothing. On the last pagination page, the button does get output, but the URL of NEWER POSTS link gets set to: http://example.com/news/{auto_path} instead of the correct pagination URL.
(Not to mention my template only has 81 lines.)
Based on these two examples, there appears to be a problem with how ExpressionEngine interprets {if} blocks when they are within the {paginate} tag’s {if next_page} and {if previous_page} tag blocks.
Has anyone else come across this problem and/or have an idea how this could be fixed?