Login | Sign up | Toll-Free: 1-800-752-0455



9 posts by 4 authors in: Forums > CMS Builder
Last Post: January 13, 2017

If you're using the permalinks plugin, you can use this table to very quickly generate the list of URLs for a sitemap file. The only catch is that you need to filter out any of those that are marked as "OLD". 

1. Setup a file named sitemap.php with this code...

  header('Content-type: application/xml');
   list($permalinksRecords, $permalinksMetaData) = getRecords(array(
    'tableName'   => '_permalinks',
    'loadUploads' => false,
    'allowSearch' => false,
    "where" => "!old",
  $base_url = "http://www.yoursite.com/";

  $output = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
  $output .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
  echo $output;
    <loc><?php echo $base_url; ?></loc>
  <?php foreach ($permalinksRecords as $record): ?>
      <loc><?php echo $base_url; ?><?php echo $record['permalink'] ?></loc>
  <?php endforeach ?>

2. and in your robots.txt, add this line...

Sitemap: http://www.yoursite.com/sitemap.php

Hi there.

Thanks for posting. This looks like a great tip.

Anyone who gives it shot, post the results :).


Ross Fairbairn - Consulting

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

We've been using the permalinks database to create xml sitemaps in a very similar fashion as this, and save ours as sitemap.xml.php and reference in robots.txt file.

In addition, we add the cmsb special field "hidden" to toggle sitemap visibility where needed (dev pages, etc.).


I was using the permalinks table to generate the sitemap, but started running into problems at times, especially since I use a category section to layout the structure of my site, I ended up with permalinks to pages that didn't really exist (parent categories with no content). Managing that by hiding records was a bit of a hassle, and I don't give clients access to that admin data anyway.

So I now generate the sitemap directly from the category menu which normally runs my entire site navigation, using the permalinks field.  I can not show the record if it has a child, or hidden etc.  I then add in additional section views for more modular / list type sections such as blog items and products.


Tim Forrest
Toledoh Enterprises

Hey Tim,

Your described approach is how we almost always handle our xml sitemap generation, as the majority of our sites are also managed in the same dynamic fashion via category menu. The method described by mizrahi does work fine for sites built with single record editors though.

For parent level categories without content, we've been using a checkbox field "is_category_label_only". If that is ticked, then we filter it from being output to the sitemap.

On a side note, we also use that field in handling our dynamically created bootstrap main site navigation. For example, we'll use $navLink in the href -- setting it to # if it's a parent category without content, or setting it to $categoryRecord['_link'] if it's a real page.


Yep!  And similarly, sometimes I want to break out of the category page listing, so I have a field "redirect".  If I enter a path in that field, the navigation text is controlled, but I use the redirect path for the link.

(Wouldn't it be great to one day organise a CMSB conference - a 2 day sit-in to look at how we all approach different challenges.)


Tim Forrest
Toledoh Enterprises

I would go to this!

The "redirect" field is a good idea.

We've been using an Admin Access Only field called "custom_include" to include separate php files for custom page views (modular / list type sections).

For example, News Listing would be handled by a separate multi-record editor - we'd put all the News Listings code/layout on it's own php include file called "news-listings-view.php" and save that custom page views file name in the "custom_include" field. Then for field validation we use a modified version of the code block CMSB uses for checking Viewer Urls.

Similar again!  I create a list of "includes" that are available via a select box, then use;

<?php if ($selectedCategory['include']==1) { include("...");} ?>
<?php if ($selectedCategory['include']==2) { include("...");} ?>

Each of the includes I have in a folder I include in any site full of standard "things" I include such as email forms, various layouts of list pages etc.


Tim Forrest
Toledoh Enterprises