2

how can i apply pagination-with-relnext-and-relprev to pagination in the header?

i want to add

<link rel="next" href="http://www.example.com/article?story=abc&page=3" />

and

<link rel="prev" href="http://www.example.com/article?story=abc&page=1" />

on pagination page 2, and so on. with an exception for the first and last page. last page should only contain the rel="prev" and the first page should only contain rel="next"

this would not be too hard to get in the body within the current {paginate} tags, as i see in many other solutions, but i want it in the header as stated in the article above by Google.

anyone has an idea how to approach this problem?

5
  • What do you want to paginate? Span an article across multiple pages? Or link a series of articles?
    – Sobral
    Commented Jun 24, 2014 at 14:41
  • i want to paginate entries multiple article links per page
    – 77120
    Commented Jun 24, 2014 at 14:54
  • Ok, but do you want to put every product on a page or link the pages of the list of products?
    – Sobral
    Commented Jun 24, 2014 at 14:57
  • the product list :)
    – 77120
    Commented Jun 24, 2014 at 14:58
  • 1
    I see. There's more than one way to do this. How are you filling the <title>? Please, add a sample code to your question.
    – Sobral
    Commented Jun 24, 2014 at 16:34

2 Answers 2

1

Let's try with a sample pagination code from the user guide.

{paginate}
  {pagination_links}
    <ul>
      {first_page}
        <li><a href="{pagination_url}" class="page-first">First Page</a></li>
      {/first_page}

      {previous_page}
        <li><a href="{pagination_url}" class="page-previous">Previous Page</a></li>
        {layout:set name="previous_page"}{pagination_url}{/layout:set}
      {/previous_page}

      {page}
        <li><a href="{pagination_url}" class="page-{pagination_page_number} {if current_page}active{/if}">{pagination_page_number}</a></li>
      {/page}

      {next_page}
        {layout:set name="next_page"}{pagination_url}{/layout:set}
        <li><a href="{pagination_url}" class="page-next">Next Page</a></li>
      {/next_page}

      {last_page}
        <li><a href="{pagination_url}" class="page-last">Last Page</a></li>
      {/last_page}
    </ul>
  {/pagination_links}
{/paginate}

On the pagination tags, set the layout variables.

(Yeah, I know! layout:set should have a output='yes' parameter!).

Then, on your layout template:

{if layout:next_page}<link rel="next" href="{layout:next_page}" />{/if}
{if layout:previous_page}<link rel="prev" href="{layout:previous_page}" />{/if}

This could work with an embed too.

0

The only way I could create rel prev and next links within paginated pages was to create a separate extension. This is where pagination is displayed with /P## within the url for the page numbers. This works fine for what I need and have tested it on EE2.9 but should work on later versions.

I'd be interested to know if this is of use to anyone as this has been a long standing problem where I've not been able to create rel links before.

It can be downloaded from here: https://github.com/ignetic/ee-pagination-rel-links

1
  • Can you, please, try my code? I can't do that right now.
    – Sobral
    Commented Jun 15, 2015 at 20:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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