Welcome to Vortx Community Forum, where you can ask questions and receive answers from the staff at Vortx and other members of the community.

If you had a user account on our previous forums website, you will need to register a new account here.

Learn more about...


How to identify last of paginated pages

I'm trying to set up SEO pagination for my category and product pages. This involves setting link attributes with rel="next" and rel="prev" in the page head whenever a pageNum query string is present.

It's simple enough to do for all the pages in a unit except the last one. The pageNum will always be >= 1, with 1 being the first page in the sequence and has only a rel="next" link. All the pages between the first and last will have both. The last page will have only a rel="prev" link.

So far, I've tried using an XmlPackage in the head of the root master page, but that's not sensitive to different entity types and is out of scope of the "pages" data.

I've also tried working with this data from the entity-specific XmlPackages, and then passing the attributes for the <link> to a method in a customer XsltExtension, but I can't seem to get access to the Page.Header from here to add the HtmlLink object.


I'm appreciative of any direction and efforts you all can put in to it. If I arrive a solution for this I'll post it here.
asked Feb 10, 2014 in MultiStore by Chris (3,685 points)

1 Answer

0 votes

I think this was a case of being entirely too close to the problem for too long.

Here's a full rundown of how to implement pagination tagging for search engines on your category pages.

All of my categories use an xml package titled 'entity.ocr.gridwithprices.xml.config', and I have a custom XsltExtension file in my App_Code folder mapped to 'xmlns:ryan'.

I placed the following XSLT code in the <xsl:template match="/"> element:

        <xsl:if test="count(/root/QueryString/pagenum) &gt; 0">
            <xsl:when test="/root/QueryString/pagenum = 1">
              <xsl:variable name="paginationNext" select="concat(/root/System/StoreUrl,/root/System/PageName,'?pagenum&#61;',(/root/QueryString/pagenum)+1)" />
              <xsl:value-of select="ryan:AddPagination($paginationNext, 'next')" />
            <xsl:when test="(/root/QueryString/pagenum) = (/root/Products2/Product/pages)">
              <xsl:variable name="paginationPrev" select="concat(/root/System/StoreUrl,/root/System/PageName,'?pagenum&#61;',(/root/Products2/Product/pages)-1)" />
              <xsl:value-of select="ryan:AddPagination($paginationPrev, 'prev')" />
              <xsl:variable name="paginationNext" select="concat(/root/System/StoreUrl,/root/System/PageName,'?pagenum&#61;',(/root/QueryString/pagenum)+1)" />
              <xsl:variable name="paginationPrev" select="concat(/root/System/StoreUrl,/root/System/PageName,'?pagenum&#61;',(/root/QueryString/pagenum)-1)" />
              <xsl:value-of select="ryan:AddPagination($paginationNext, 'next')" />
              <xsl:value-of select="ryan:AddPagination($paginationPrev, 'prev')" />

Basically, this checks if there is a query string 'pagenum' in the XML, and then processes the conditions for 'next' and 'prev' relationships. If they match, the AddPagination() method is run from the XsltExtension mapped to 'ryan'.

That function looks like this:

        public void AddPagination(string paginationHref, string paginationRel)
            HtmlLink pLink = new HtmlLink();
            pLink.Attributes.Add("href", paginationHref);
            pLink.Attributes.Add("rel", paginationRel);

            Page page = HttpContext.Current.Handler as Page;

Checking the source code of the loaded page, I see the following:

<link href="https://.../c-47-helpers-and-accessories.aspx?pagenum=2" rel="next" /></head>


answered Feb 11, 2014 by Chris (3,685 points)