Announcement

Collapse
No announcement yet.

Template Based Sitemap: PageList_Load_Offset_Item_Unassigned No Longer Works

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Template Based Sitemap: PageList_Load_Offset_Item_Unassigned No Longer Works

    I set up a custom Sitemap a while back using a Template Based Feed and the code I used in the footer no longer seems to work.

    This code was based off SteveoSoule 's example here: https://gist.github.com/steveosoule/...3bbd1167995618

    I have no idea when or why it stopped working.

    Code:
    <mvt:do file="g.Module_Feature_TUI_DB" name="l.success" value="Item_Load_Code( 'sitemap_exclude', l.item )" />
    <mvt:do file="g.Module_Feature_TUI_DB" name="l.success" value="PageList_Load_Offset_Item_Unassigned( l.item:id, 0, '', '', 999, l.next_offset, l.pages )" />
    <mvt:assign name="l.result" value="miva_array_filter_ref( l.pages, 0, l.page, 'l.page:admin EQ 0', l.settings:sitemap_pages )" />
    <mvt:foreach iterator="page" array="sitemap_pages">
        <mvt:do file="g.Module_Feature_URI_DB" name="l.have_page_uri" value="URI_Load_Page_Canonical(l.settings:page:code, l.settings:page_info)" />
        <mvt:if expr="l.have_page_uri">
            <url>&mvt:eol:crlf;
                <mvt:assign name="l.settings:page:link" value="'https://' $ g.domain:name $ l.settings:page_info:uri" />
                <loc>&mvt:page:link;</loc>&mvt:eol:crlf;
                <lastmod>&mvt:global:current_date;</lastmod>&mvt:eol:crlf;
                <changefreq>monthly</changefreq>&mvt:eol:crlf;
            </url>&mvt:eol:crlf;
        </mvt:if>
    </mvt:foreach>
    Any help or insights would be appreciated.
    Nick Harkins
    www.loveisarose.com

    #2
    SidFeyDesigns this snippet is no longer working because the PageList_Load_Offset_Item_Unassigned has been depreciated:

    https://github.com/mivaecommerce/miv...mv#L4426-L4428

    Here is an updated version that should work by just replacing the code completely.

    EDITED: SEE SNIPPET BELOW FOR CORRERCTED VERSION

    Code:
    ...
    Last edited by Nick; 01-27-26, 08:51 AM.
    Nicholas Adkins
    Technical Training Specialist / Miva, Inc.
    [email protected]
    https://www.miva.com/mivalearn

    Comment


      #3
      Thanks Nick .

      I needed to adjust 1 line but it is working now. I appreciate the help.

      Code:
      <mvt:do file="g.Module_Feature_TUI_DB" name="l.success_item" value="Item_Load_Code( 'sitemap_exclude', l.item )" />
      <mvt:do file="g.Module_Feature_TUI_DB" name="l.count" value="PageList_Load_Item( l.item:id, l.settings:pages )" />
      <mvt:do file="g.Module_Feature_TUI_DB" name="l.count" value="PageList_Load_All( l.settings:pagelist )" />
      <mvt:foreach iterator="page" array="pagelist">
         <mvt:if expr="NOT (l.settings:page:code CIN l.settings:pages)">
              <mvt:do file="g.Module_Feature_URI_DB" name="l.have_page_uri" value="URI_Load_Page_Canonical(l.settings:page:code, l.settings:page_info)" />
              <mvt:if expr="l.have_page_uri">
                  <url>&mvt:eol:crlf;
                      <mvt:assign name="l.settings:page:link" value="'https://' $ g.domain:name $ l.settings:page_info:uri" />
                      <loc>&mvt:page:link;</loc>&mvt:eol:crlf;
                      <lastmod>&mvt:global:current_date;</lastmod>&mvt:eol:crlf;
                      <changefreq>monthly</changefreq>&mvt:eol:crlf;
                  </url>&mvt:eol:crlf;
              </mvt:if>
          </mvt:if>
      </mvt:foreach>
      Nick Harkins
      www.loveisarose.com

      Comment


        #4
        I just updated the original gist to make it continue to work now that "PageList_Load_Offset_Item_Unassigned" has been deprecated:

        Code:
        <mvt:do file="g.Module_Library_Utilities" name="l.settings:lastmod" value="Format_RFC3339_DateTime( s.time_t )" />
        <mvt:do file="g.Module_Feature_TUI_DB" name="l.result" value="Item_Load_Code( 'sitemap_exclude', l.item )" />
        <mvt:do file="g.Module_Feature_TUI_DB" name="l.result" value="PageList_Load_Item( l.item:id, l.excluded_pages )" />
        <mvt:do file="g.Module_Feature_TUI_DB" name="l.result" value="PageList_Load_All_Runtime( l.settings:pages )" />
        
        <mvt:foreach iterator="page" array="pages">
        <mvt:assign name="l.is_excluded" value="miva_array_search( l.excluded_pages, 1, l.excluded_page, 'l.excluded_page:code EQ l.settings:page:code' )" />
        
        <mvt:if expr="l.is_excluded">
        <mvt:foreachcontinue />
        </mvt:if>
        
        <mvt:do file="g.Module_Feature_URI_UT" name="l.settings:page:url" value="Store_Page_URL( l.settings:page, l.flags )" />
        
        <url>&mvt:eol:crlf;
        <loc>&mvte:page:url;</loc>&mvt:eol:crlf;
        <lastmod>&mvte:lastmod;</lastmod>&mvt:eol:crlf;
        <changefreq>monthly</changefreq>&mvt:eol:crlf;
        </url>&mvt:eol:crlf;
        </mvt:foreach>
        It has some enhancements that may be worth considering:
        1. Instead of PageList_Load_All() it uses PageList_Load_All_Runtime() which will automatically exclude emails, batch-reports, and fragments.
        2. Determining if the pages were excluded has been made more accurate where page-codes must equal the excluded page-code; not just be found within it. (i.e. using the CIN match can generate some false positives; like if "CTUS_TEST" was excluded, then the "CTUS" page could be excluded because "CTUS" is in "CTUS_TEST")
        3. Instead of URI_Load_Page_Canonical() it uses Store_Page_URL() which will load the URL according to the store's URI settings (Long, Legacy, URI, etc.); not just the URI
        4. The empty lastmod/g.current_date output has been fixed by using Format_RFC3339_DateTime( s.time_t )

        Comment


          #5
          Thank you SteveoSoule ! This is Great and works perfectly!

          I was originally using this in the header template for the lastmod date on everything.

          Code:
          <mvt:assign name = "l.settings:month" value = "padl( time_t_month( s.time_t, 'local' ), 2, '0' )" />
          <mvt:assign name = "l.settings:day" value = "padl( time_t_dayofmonth( s.time_t, 'local' ), 2, '0' )" />
          <mvt:assign name = "l.settings:year" value = "time_t_year( s.time_t, 'local' )" />
          <mvt:assign name="g.current_date" value="l.settings:year $ '-' $ l.settings:month $ '-' $ l.settings:day" />
          I took your example and added Format_RFC3339_DateTime( l.settings:category:dt_updated ) to the Header Template for the categories iterator and also used Format_RFC3339_DateTime( l.settings:record:dt_updated ) in the Iterator Template.

          I also took the Store_Page_URL example and used Store_Category_URL in the Header Template for the categories iterator.

          Header Template:
          Code:
          <mvt:if expr="ISNULL g.categories_offset"><mvt:assign name="g.categories_offset" value="0" /></mvt:if>
          <mvt:assign name="l.search" value="1" />
          <mvt:assign name="l.searchable_fields" value="'active'" />
          <mvt:do file="g.Module_Library_DB" name="l.success" value="CategoryList_Load_Offset(g.categories_offset, l.search, l.searchable_fields, g.categories_max, g.categories_next_offset, l.settings:categories)" />
          <mvt:foreach iterator="category" array="categories">
              <mvt:do file="g.Module_Feature_URI_UT" name="l.settings:category:url" value="Store_Category_URL( l.settings:category, l.flags )" />
              <mvt:do file="g.Module_Library_Utilities" name="l.settings:category:lastmod" value="Format_RFC3339_DateTime( l.settings:category:dt_updated )" />
              <url>&mvt:eol:crlf;
                  <loc>&mvt:category:url;</loc>&mvt:eol:crlf;
                  <lastmod>&mvte:category:lastmod;</lastmod>&mvt:eol:crlf;
                  <changefreq>monthly</changefreq>&mvt:eol:crlf;
              </url>&mvt:eol:crlf;
          </mvt:foreach>
          Iterator Template:
          Code:
          <mvt:do file="g.Module_Library_Utilities" name="l.settings:record:lastmod" value="Format_RFC3339_DateTime( l.settings:record:dt_updated )" />
          <url>&mvt:eol:crlf;
              <loc>&mvt:record:url;</loc>&mvt:eol:crlf;
              <lastmod>&mvte:record:lastmod;</lastmod>&mvt:eol:crlf;
              <changefreq>monthly</changefreq>&mvt:eol:crlf;
              <image:image>&mvt:eol:crlf;
                  <image:loc>&mvt:global:secure_baseurl;&mvt:record:customfield:main;</image:loc>&mvt:eol:crlf;
                  <image:title>&mvte:record:name;</image:title>&mvt:eol:crlf;
              </image:image>&mvt:eol:crlf;
          </url>&mvt:eol:crlf;
          These were some nice updates to the custom sitemap that includes product images. I appreciate the help!

          Cheers!
          Last edited by SidFeyDesigns; 01-28-26, 07:51 PM.
          Nick Harkins
          www.loveisarose.com

          Comment


            #6
            You're welcome SidFeyDesigns . I'm glad that helped!

            I would recommend that you use Runtime_CategoryList_Load_All instead of CategoryList_Load_Offset because it takes into account Availability Groups too; not just :active

            Code:
            <mvt:do file="g.Module_Library_DB" name="l.count" value="Runtime_CategoryList_Load_All( categories var )" />
            Also, I'm curious if you've tried the "Marketing > Feeds > Standard Sitemap Protocol" to build your sitemap.xml without having to use template-code? Is there a reason you're using the template-code route instead of the Standard Sitemap Protocol feed?

            Comment


              #7
              Once again, thank you for the better alternative SteveoSoule .

              This template based sitemap was set up around 2018 after the site was updated from Miva 5 PR8 to Miva 9. At the time the site owner wanted to include product images in the sitemap for more efficient indexing of those images.

              I'm not sure if that matters much now in 2026 but I don't think it will hurt to still have them included.
              Nick Harkins
              www.loveisarose.com

              Comment

              Working...
              X