Problems, need help? Have a tip or advice? Post it here.
8 posts Page 1 of 1
Using this tutorial (viewtopic.php?f=8&t=7173) to generate dynamic sitemaps, I implemented the following code in sitemap.php, which is hosted under "http://example.com/sitemap":

Code: Select all
<?php require_once( 'cmsadmin/cms.php' ); ?>
<cms:content_type 'text/xml' /><cms:concat '<' '?xml version="1.0" encoding="' k_site_charset '"?' '>' />
<urlset
      xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
            http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">

<cms:templates order='asc' >
    <cms:pages masterpage=k_template_name>
        <url>
           <loc><cms:show k_page_link /></loc>
           <lastmod><cms:date "<cms:if k_page_modification_date='0000-00-00 00:00:00'><cms:show k_page_date /><cms:else /><cms:show k_page_modification_date /></cms:if>" format='Y-m-d\TH:i:s+00:00' gmt='1' /></lastmod>
        </url>
    </cms:pages>
</cms:templates>

</urlset>
<?php COUCH::invoke(); ?>


The code works and the sitemap gets generated, however, there are quite some pages missing.

I used to generate the sitemap manually with https://www.xml-sitemaps.com/ and I count quite a large mismatch. Obviously pages that are not CouchCMS-generated on the domain will not show up, but important pages like "http://example.com/blog" are missing. I think mainly the blog-category listings (organized in folders) are not present.

Any idea if it is possible to include those?

Also is it possible to exclude the globals.php template (http://example.com/globals/)?
Looks like you have listed pages of templates only. Not templates itself.
Maybe run a separate loop for templates only. Can you try this and report what are the differences left?

As to excluding, a conditional can help:
Code: Select all
<cms:if k_template_name!='globals.php'>
   ... show..
</cms:if>

http://docs.couchcms.com/tags-reference/if.html
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
We can add the home-view and folder-views as follows -
Code: Select all
<cms:templates order='asc' >
    <url>
        <loc><cms:show k_template_link /></loc>
    </url>
   
    <cms:folders masterpage=k_template_name>
        <url>
            <loc><cms:show k_folder_link /></loc>
        </url>
    </cms:folders>
   
    <cms:pages masterpage=k_template_name>
        <url>
           <loc><cms:show k_page_link /></loc>
           <lastmod><cms:date "<cms:if k_page_modification_date='0000-00-00 00:00:00'><cms:show k_page_date /><cms:else /><cms:show k_page_modification_date /></cms:if>" format='Y-m-d\TH:i:s+00:00' gmt='1' /></lastmod>
        </url>
    </cms:pages>
</cms:templates>

Does this help?
Thanks KK, that basically lists all pages, but it creates double entries for the top-level templates that do not have further sub-folders: 1 with the time-stamp and one without.

Also, is it possible to exclude the globals.php template?
but it creates double entries for the top-level templates that do not have further sub-folders: 1 with the time-stamp and one without.
Actually that would happen for non-clonable templates. Please try the following -
Code: Select all
<cms:templates order='asc' >
    <url>
        <loc><cms:show k_template_link /></loc>
    </url>
   
    <cms:folders masterpage=k_template_name>
        <url>
            <loc><cms:show k_folder_link /></loc>
        </url>
    </cms:folders>
   
    <cms:if k_template_is_clonable >
        <cms:pages masterpage=k_template_name>
            <url>
               <loc><cms:show k_page_link /></loc>
               <lastmod><cms:date "<cms:if k_page_modification_date='0000-00-00 00:00:00'><cms:show k_page_date /><cms:else /><cms:show k_page_modification_date /></cms:if>" format='Y-m-d\TH:i:s+00:00' gmt='1' /></lastmod>
            </url>
        </cms:pages>
    </cms:if>
</cms:templates>

Also, is it possible to exclude the globals.php template?

@trendoman already answered that above. You can add a check like this
Code: Select all
<cms:templates order='asc' >
    <cms:if k_template_name!='globals.php'>
        <url>
            <loc><cms:show k_template_link /></loc>
        </url>
       
        ..
        ..
       
    </cms:if>
</cms:templates>
Ok, that works.

Do the folder variables carry the date as well, e.g. k_folder_modification_date to include them in <lastmod>?

A last complication:

Is it possible to exclude specific folder levels?

I am dealing with a portfolio, which is listed on http://example.com/work/. Now, the different portfolio items are listed in categories, e.g. category a, b, c. (http://example/work/category-a/).
However, the page is build in a way that if you visit a category-link, this would lead back to http://example.com/work/. Only the individual portfolio items have their own pages, e.g. http://example/work/category-a/portofolio-item.html.

From a SEO-perspective, listing the portfolio-categories would create duplicate content, which is bad.

Is there a way to exclude the categories, e.g. http://example/work/category-a/, but keep the individual portfolio items, e.g. http://example/work/category-a/portofolio-item.html ?
JD wrote: Ok, that works.

Do the folder variables carry the date as well, e.g. k_folder_modification_date to include them in <lastmod>?

A last complication:

Is it possible to exclude specific folder levels?

I am dealing with a portfolio, which is listed on http://example.com/work/. Now, the different portfolio items are listed in categories, e.g. category a, b, c. (http://example/work/category-a/).
However, the page is build in a way that if you visit a category-link, this would lead back to http://example.com/work/. Only the individual portfolio items have their own pages, e.g. http://example/work/category-a/portofolio-item.html.

From a SEO-perspective, listing the portfolio-categories would create duplicate content, which is bad.

Is there a way to exclude the categories, e.g. http://example/work/category-a/, but keep the individual portfolio items, e.g. http://example/work/category-a/portofolio-item.html ?


If you have 301 redirects from the category urls back to /work/ Google won't see it as duplicated content and you should be fine.'however, you can remove them from the site map (and I would too). I've only had a quick look at the code but it seems like you just need to either remove the <cms:folders> block (don't do this if you have multiple templates with folders that you DO want output.) or wrap that block in an if statement:

Code: Select all
<cms:if k_template_name!='YOURTEMPLATE.php'></cms:if>


The pages should be listed by the <cms:pages> block so they won't be affected.

Furthermore, you could more easily filter the folders using the "depth" or "exclude" parameters, see: http://docs.couchcms.com/concepts/using-folders.html However this may not be desirable on here as it outputs folders from all templates, using depth would affect them all.

Sorry if I missed anything, replying from my phone at work isn't easy!
Image
I ended now up with the following version, which seems to include the required folders and exclude the work-related folders:

Code: Select all
<?php require_once( 'cmsadmin/cms.php' ); ?>
<cms:content_type 'text/xml' /><cms:concat '<' '?xml version="1.0" encoding="' k_site_charset '"?' '>' />
<urlset
      xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
            http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">

<cms:templates order='asc' >
    <cms:if k_template_name!='globals.php'>
        <url>
            <loc><cms:show k_template_link /></loc>
        </url>

        <cms:if k_template_name!='work.php'>

            <cms:folders masterpage=k_template_name>
                <url>
                    <loc><cms:show k_folder_link /></loc>
                </url>
            </cms:folders>

        </cms:if>

        <cms:if k_template_is_clonable >
            <cms:pages masterpage=k_template_name>
                <url>
                    <loc><cms:show k_page_link /></loc>
                </url>
            </cms:pages>
        </cms:if>

    </cms:if>
</cms:templates>

</urlset>
<?php COUCH::invoke(); ?>
8 posts Page 1 of 1