May I introduce my first plugin, BU Search Pagination, built to scratch an itch on a project that’s coming to an introduction forum near you soon. This has been lying around for a little while, largely because I’ve been too busy to attend to it properly, but I see that it’s time to officially release it into the world and find out what people make of it. A few have already had a chance to play with it, but now it’s time for you too.
Add this into your template when you wish to have greater control over customising the pagination tags on your search results page.
The plugin bases the output of its pagination on the search results (per page limit) and result_page parameters set in your search form tag and the total number of results calculated by the Search Module.
It is, as said, my first plugin, so perhaps a bit rough and ready. Let me know what you think and if there’s anything I can do to improve it for you.
Still to do - add in EE standard pagination_links form too
You can use it one of 2 ways.
As a tag pair with variables. Or as a single tag supplying it with a parameter. The former is probably the most useful way. The latter is retained as it was the first way I built it, so figured I’d leave it available anyway.
The tag pair:
{exp:bu_search_pagination}{/exp:bu_search_pagination}
Variables available within:
{current_page}
{total_pages}
{prev_page_path}
{next_page_path}
{first_page_path}
{last_page_path}
As a single tag with the ‘type’ parameter set to display the current_page number:
{exp:bu_search_pagination type='current_page'}
All the variants:
{exp:bu_search_pagination type='current_page'}
{exp:bu_search_pagination type='total_pages'}
{exp:bu_search_pagination type='prev_page_path'}
{exp:bu_search_pagination type='next_page_path'}
{exp:bu_search_pagination type='first_page_path'}
{exp:bu_search_pagination type='last_page_path'}
Example usage, using the tag pair form:
{exp:bu_search_pagination}
{if prev_page_path}
<a href="http://{path={prev_page_path}}">Prev</a>
{/if}
Page {current_page} of {total_pages}
{if next_page_path}
<a href="http://{path={next_page_path}}">Next</a>
{/if}
{/exp:bu_search_pagination}
Thanks to d3i and particularly Masuga for suggestions and requests that have encouraged development.
Latest version available for download from the BU Search Pagination page on my website.
Hope you find it useful.
Just added a couple of new variables in response to 1) in this thread so you can get reference to the results on the page too:
{page_results_first}
and
{page_results_last}
.
e.g. on the 2nd page where you have 5 results per page, page_results_first would be 6, page_results_last would be 10, so you can display ‘results 6 - 10’ with this code:
{exp:bu_search_pagination}
results {page_results_first} - {page_results_last}
{/exp:bu_search_pagination}
Hopefully get to 2) pagination_links in a day or three
Version 1.2.0 sees a new pair variable added so that you can output and style pagination links for search result pages.
{pagination_pages}
{/pagination_pages}
This has 2 parameters available to it -
format
and
limit
pagination_pages has the following single variables available within it
{count}
{page_number}
{page_path}
count
tells you what position you are on in the pagination_pages loop.
page_number
tells you the page number for the current result page processed.
page_path
provides a link path for the current result page processed.
The ‘format’ parameter for pagination_pages allows you to change the pagination so that it is split up into blocks of pages. By default each block contains up to 5 sets of result pages. The ‘limit’ parameter allows you to change that.
For example, if you had 19 pages of results and a ‘limit’ of 4, pages 1-4 would be the first block, 5-8 the second and so on. The final block would have 3 pages.
If you’ve specified a ‘format’ parameter of ‘block’ then the following single variables also become available within pagination_pages:
{total_block_pages}
{prev_block_path}
{prev_block_pages}
{next_block_path}
{next_block_pages}
total_block_pages
just reflects the number of blocks that the results have been split into. If you don’t specify a ‘limit’ this will be 5 as that’s the default limit.
prev_block_path
provides the link back to the first page within the previous block.
prev_block_pages
provides a reference for the pages contained within the previous block. This follows the format 1 - 4, 5 - 8 etc. Neither of these two variables will be available on pages within the first block.
next_block_path
provides the link to the first page within the next block.
next_block_pages
provides a reference for the pages contained within the next block. This follows the format 4 - 8, 9 - 12 etc. Neither of these two variables will be available on pages within the last block.
Here’s an example using the pagination_pages pair variable:
{exp:bu_search_pagination}
{pagination_pages format='block' limit='10'}
{if prev_block_path!='' AND count==1}
<a href="http://{path={prev_block_path}}">{prev_block_pages}</a>
{/if}
{if page_number==current_page}
{page_number}
{if:else}
<a href="http://{path={page_path}}">{page_number}</a>
{/if}
{if next_block_path!='' AND count==total_block_pages}
<a href="http://{path={next_block_path}}">{next_block_pages}</a>
{/if}
{/pagination_pages}
{/exp:bu_search_pagination}
Thanks for this! Have you been able to make this work while displaying tag search results from the solspace {exp:tag:search_results} module? Right now my search results are displaying, then my tag results, then the pagination links, as opposed to cycling through all of the search results and then listing the tags results on the last page. Any hints? Thanks!
Awesome plugin!
For some reason I can’t seem to be able to use the
{exp:search:total_results}
tag inside it though. It just spits out some garbage like “M20o93H7pQ09L8X1t49cHY01Z5j4TT91fGfr” instead of the actual number. Any thoughts on this or how can I get the total results number without going the PHP route?
Basically, I am trying to show something along these lines: “Showing 1-10 out of 27 results”
@bb6600 - Looks like it’s muddling things up. Have you tried separating the two things out so that they’re not nested? e.g.
{exp:bu_search_pagination}
Showing {page_results_first} - {page_results_last}
{/exp:bu_search_pagination}
{exp:search:total_results}
out of {total_results} results
{/exp:search:total_results}
Something like that?
@lizlux Sorry for missing your post - think I’ve become unsubscribed from this thread. I’ve not tried this plugin yet in combination with Solspace’s Tags module. I’ll try and replicate when I get a chance to use Tags and Search together. If you’ve come up with any solutions, please post them here.
@Verdel Automatisering Again, sorry for missing you. Looks like you were trying to show pages links. The code posted above for pagination_pages should cover you.
@jamesa Thanks - glad it’s been useful.
Thanks again BU!
Just in case someone else is interested in this, I’ll post my complete code for generating a pagination area that looks something like this:
showing 1-10 out of 44 results prev 1 2 3 4 next
{exp:bu_search_pagination}showing <strong>{page_results_first} - {page_results_last}</strong>{/exp:bu_search_pagination} out of <strong>{exp:search:total_results} result{if "{exp:search:total_results}" != 1}s{/if}</strong>
{exp:bu_search_pagination}<ul>
<li>< a href="{path={prev_page_path}}"{if prev_page_path}{if:else} class="inactive"{/if}>prev</a></li>
{pagination_pages}
{if page_number == current_page}<li><a href="http://{path={page_path}}" class="active">{page_number}</a></li>
{if:else}<li><a href="http://{path={page_path}}">{page_number}</a></li>{/if}
{/pagination_pages}
<li>< a href="{path={next_page_path}}"{if next_page_path}{if:else} class="inactive"{/if}>next</a></li>
</ul>{/exp:bu_search_pagination}
Remove the extra space before the next/prev ‘a’ tags.
It’s complete with CSS classes to highlight the current page and inactive next/prev links.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.