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}
3
  • 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, 2012 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, 2013 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, 2013 at 16:02

3 Answers 3

8

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

3
  • 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, 2012 at 16:00
  • 1
    @jmulkey That's a bug, see this bug report for a patch.
    – Dom Stubbs
    Dec 18, 2012 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, 2012 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.

4
  • 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, 2012 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, 2012 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, 2012 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, 2012 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 agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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