Hidden pages in Permalinks table

By Toledoh - January 14, 2016

Hi Guys.

If a page is "hidden", or outside of the publishDate / removeDate, is there any way to mark it as hidden, or "old" in the permalinks table?

I'm using this table to maintain the sitemap.xml, and google is looking at pages that are not currently published and therefore returning 404.

Cheers,

Tim (toledoh.com.au)

Hey Tim,

What code are you using to generate the sitemap? Could you post it here for me? It might be possible to add some code that checks if a particular record in a section is hidden or expired and stop it added.

Cheers,

Greg

Greg Thomas







PHP Programmer - interactivetools.com

Thanks Tim, 

I've written some example code that will get a linked record, so that we can check if it's hidden or not:

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
  /* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */
  
  // load viewer library
  $libraryPath = 'cmsb/lib/viewer_functions.php';
  $dirsToCheck = array('C:/wamp/www/','','../','../../','../../../');
  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

   // load records from '_permalinks'
  list($_permalinksRecords, $_permalinksMetaData) = getRecords(array(
    'tableName' => '_permalinks',
    'orderBy' => '', // use default database order
    'loadUploads' => false,
    'allowSearch' => false,
  ));
  
?>
<?php header('Content-type: application/xml; charset=utf-8'); ?><?php echo '<'.'?xml version="1.0" encoding="UTF-8"?>'; ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <?php foreach ($_permalinksRecords as $record): ?>
    <?php
      if($record['tableName'] && $record['recordNum']){
        $linkedRecord = mysql_get($record['tableName'], $record['recordNum']);
      }
    ?>
    <?php if (!$record['old'] && !@$linkedRecord['hidden']): ?>
      <url>
        <loc>http://<?php echo $_SERVER['HTTP_HOST']; ?><?php echo $record['_link'] ?></loc>
        <lastmod><?php echo date('Y-m-d', strtotime($record['updatedDate'])) ?></lastmod>
        <changefreq>weekly</changefreq> 
        <priority>0.5</priority>
      </url>
    <?php endif ?> 
  <?php endforeach ?>
</urlset>

So this code works by checking if the table name and record num are set for a permalink, if they are it retrieves the linked record and sets it to the variable $linkedRecord which can then be checked to see if a hidden variable is set.

You could also use the $linkedRecord variable to check if a start and end date are set as well.

Let me know if you have any questions. 

Cheers,

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By Toledoh - January 14, 2016

Perfect - thanks!

Cheers,

Tim (toledoh.com.au)