We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13226
    • 953 Posts
    Hi All

    Just to clear things - this topic is not the standard pagination that snippets like PrevJumpNext create.

    This is similar to rel canonical in the <head> tag.

    As I was reading Googles Webmaster Central Blog I came across this post


    Example:

    ("http" and "www" have been removed from the links as the forum generates real URI's when used)

    Main Url - domainname.com/mypage?pid=1

    Paginated content creates the following:

    domainname.com/mypage?pid=1&pn=1
    domainname.com/mypage?pid=1&pn=2
    domainname.com/mypage?pid=1&pn=3
    domainname.com/mypage?pid=1&pn=4

    What should then be included in the head for the individual URI's:

    &pn=1 should have:
    <link rel="next" href="domainname.com/mypage?pid=1&pn=2" />
    
    &pn=2 should have:
    <link rel="prev" href="domainname.com/mypage?pid=1&pn=1" />
    <link rel="next" href="domainname.com/mypage?pid=1&pn=3" />
    
    &pn=3 should have:
    <link rel="prev" href="domainname.com/mypage?pid=1&pn=2" />
    <link rel="next" href="domainname.com/mypage?pid=1&pn=4" />
    
    &pn=4 should have:
    <link rel="prev" href="domainname.com/mypage?pid=1&pn=3" />
    


    Anyone know if this is possible or has already been worked on for Evo and Revo ?

    Cheers [ed. note: iusemodx last edited this post 15 years ago.]
      • 33974
      • 156 Posts
      smooth-graphics Reply #2, 15 years ago
      Where exactly is this pid and pn variables coming from?
      It should be possible in Revo.
        • 9102 ☆ A M B ☆
        • 318 Posts
        I just set this up the other day for pagination with getPage. I'll tell you about my approach, but it's a bit of a hack, so I'd love to hear if anyone has anything better. Seems to be working for me though.

        Basically, the idea is to check the placeholder containing the page nav to see if it has the anchor text of next and/or previous nav links. Then set placeholders with the appropriate rel next and rel prev links as needed.

        OK, first off, I'm using the SEO-friendly pagination technique I described here: https://forums.modx.com/thread/37914/seo-friendly-pagination-with-getpage#dis-post-214218

        I would recommend using this technique now for most situations, given Google's current stance on pagination. I posted an update to that thread with code that works for me using that technique. For your pagination scheme, you could use code something like this (I haven't tested this, so you may have to tweak it a bit). I'm assuming you're using getPage for pagination. Make sure you replace 'nex-tanchor-text' and 'prev-anchor-text' in this code with whatever the anchor text of your next and prev links are, and that you set up a property set on this snippet with the property pageVarKey set to "pn" - or you could just replace $properties['pageVarKey'] in the code with pn.

        $properties =& $scriptProperties;
        $properties['page'] = (isset($_REQUEST[$properties['pageVarKey']]) && ($page = intval($_REQUEST[$properties['pageVarKey']]))) ? $page : 1;
        
        $st_nav = $modx->getPlaceholder('page.nav');
        if ($st_nav != '') {
            $pos1 = strpos($st_nav,'prev-anchor-text');
            if($pos1 === false) {
                 $st_prevLink = '';
            }
            else {
                 $prevPageNo = $properties['page']-1;
                 $page_id = $modx->resource->get('id');
                 $st_prevLink = '<link rel="prev" href="/mypage?pid=' . $page_id . '&pn=' . $prevPageNo" />';
            }
            $pos2 = strpos($st_nav,'next-anchor-text');
            if($pos2 === false) {
                 $st_nextLink = '';
            }
            else {
                 $nextPageNo = $properties['page']+1;
                 $page_id = $modx->resource->get('id');
                 $st_prevLink = '<link rel="prev" href="/mypage?pid=' . $page_id . '&pn=' . $nextPageNo" />';
            }
        }else{
        $st_prevLink = '';
        $st_nextLink = '';
        }
        
        $modx->setPlaceholder('paginated-prev-link', $st_prevLink);
        $modx->setPlaceholder('paginated-next-link', $st_nextLink);