7

I have a search form with pagination that has a limit of 10 results per page. The problem is that the numbering of the ordered list is not continuous and starts over on each page. For example, if the search produced 15 results, page 1 would show results 1-10 and page 2 would show 1-5 rather than 11-15. Is there another way to format the results so that the numbering is continuous?

<ol>
    {exp:search:search_results paginate="both"}     
        <li>
          <h4><a href="{if page_url != ''}{page_url}{if:else}{auto_path}{/if}">{title}</a></h4> 
          {excerpt}
          <p><a href="{page_url}">{page_url}</a></p>
        </li>       
    {/exp:search:search_results}
</ol>

{if paginate}
    <div class='paginate'>
       <span class='pagecount'>{page_count}</span>&nbsp; {paginate}
    </div>
{/if}
  • Did any of the answers help you? If yes, please mark the answer correct by clicking on the checkmark to the left of the answer. – Anna_MediaGirl Dec 22 '12 at 6:20
  • 1
    @Anna_MediaGirl Thanks. I'm still learning how to use SE. I've marked the answer below from Low, but it was actually the comment from DomStubbs that solved my problem. Any way to mark a comment as the best answer? – jmulkey Jan 14 '13 at 14:29
  • You can thumb up a comment and give credit but can't select as correct answer. Best to post answer yourself and select or ask person to moved comment to a question. – Anna_MediaGirl Jan 14 '13 at 16:02
8

Do away with the <ol> and use the variable {absolute_count} instead.

  • Thanks for the reply. I've removed the <ol>, added the {absolute_count} variable, and I also removed the deprecated {if paginate} conditional and switched to the Channel style pagination. Unfortunately, it still restarts the count on page 2. {exp:search:search_results paginate="both"} {absolute_count}. <a href="{auto_path}">{title}</a> {excerpt} <a href="{page_url}">{page_url}</a> {paginate} <p>Page {current_page} of {total_pages} pages {pagination_links}</p> {/paginate} {/exp:search:search_results} – jmulkey Dec 10 '12 at 16:00
  • 1
    @jmulkey That's a bug, see this bug report for a patch. – Dom Stubbs Dec 18 '12 at 15:52
  • Thanks, @DomStubbs! I just applied the patch to mod.search.php and now the {absolute_count} variable works like a champ. – jmulkey Dec 19 '12 at 16:32
4

Low is totally correct, but I thought it might be worth adding some info about why this is necessary and how you might implement his solution.

The reason the counters on your <ol> appear 'off' is that they are automatically generated from the HTML document, which has no awareness of your pagination, so as each page is a new ordered list the first item in the list is numbered '1', no matter what page you are on.

My approach to implementing counters in the way you want is to use {absolute_count} combined with data attributes and CSS pseudo-elements, like so...

HTML;

<li data-count='{absolute_count}'>{title}</li>

CSS:

li {
  list-style: none;
}
li:before {
  content: attr(data-count);
}

This way you can still use an <ol> for semantics but get the counters the way you want them.

  • Thanks, Tom. I just tried this approach as well as Low's above, but my counters are still restarting on the pagination links. Not sure what's happening here. – jmulkey Dec 10 '12 at 19:13
  • Could you post an updated code sample? Is {absolute_count} outputting what you'd expect in your template? – Tom Davies Dec 10 '12 at 22:35
  • <ol> {exp:search:search_results paginate="bottom"} <li data-count='{absolute_count}'>. <h4><a href="{if page_url != ''}{page_url}{if:else}{auto_path}{/if}">{title}</a></h4> </li> {excerpt} <p><a href="{page_url}">{page_url}</a></p> <hr class="partial-bottom" /> {paginate} <p>Page {current_page} of {total_pages} pages {pagination_links}</p> {/paginate} {/exp:search:search_results} </ol> – jmulkey Dec 11 '12 at 15:31
  • It's outputting the count as expected on page 1 of the results, just can't seem to continue the count on the pagination links. Thanks again for taking a look. – jmulkey Dec 11 '12 at 15:33
0

This is a reported bug that has been fixed. The patch can be found here: https://support.ellislab.com/bugs/detail/18337

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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