Front-end sitemap autonav - hide some pages?

Permalink
Hi all

I have a sitemap (autonav) which generates a nice list of the pages on my site. It's set up so it doesn't honour the 'Exclude from Nav' selections on individual pages (the site map should show everything). Those pages have 'Exclude from nav' ticked for aesthetic reasons (I don't want them showing up in the menus).

Here's the custom template code I am using:

<?php 
   defined('C5_EXECUTE') or die(_("Access Denied."));
   $aBlocks = $controller->generateNav();
   $c = Page::getCurrentPage();
   echo("<ul class=\"nav sitemap\">");
   $nh = Loader::helper('navigation');
   //this will create an array of parent cIDs 
   $inspectC=$c;
   $selectedPathCIDs=array( $inspectC->getCollectionID() );
   $parentCIDnotZero=true;   
   while($parentCIDnotZero){
      $cParentID=$inspectC->cParentID;
      if(!intval($cParentID)){
         $parentCIDnotZero=false;
      }else{


The problem is that I need it to hide certain pages (like Search, Search Results, and a set of news pages that I have which will grow very large over time, making the Sitemap look terrible).

Is this possible? Is it possible to create a further page attribute (or something) to definitively remove a page from the above sitemap?

Any help much appreciated :)

melat0nin
 
olsgreen replied on at Permalink Best Answer Reply
olsgreen
Hi,

Create a page attribute called 'Exclude from Sitemap' with handle 'sitemap_exclude' and type of Boolean.

Then alter your code to read:

if (!$_c->getCollectionAttributeValue('sitemap_exclude')) { //*NEW* This evaluates your attribute and displays the link if needed
if ($c->getCollectionID() == $_c->getCollectionID()) { 
   echo('<li class="nav-selected nav-path-selected"><a class="nav-selected nav-path-selected" href="' . $pageLink . '">' . $ni->getName() . '</a>');
} elseif ( in_array($_c->getCollectionID(),$selectedPathCIDs) ) { 
   echo('<li class="nav-path-selected"><a class="nav-path-selected" href="' . $pageLink . '">' . $ni->getName() . '</a>');
} else {
  echo('<li><a href="' . $pageLink . '">' . $ni->getName() . '</a>');
}   
} //*NEW* Close


I haven't run the code this is just loosely put together.

KR

O
melat0nin replied on at Permalink Reply
melat0nin
That worked great, thanks!

(although I had to apply the attribute to each individual (existing) page which I wanted to hide, even though I set the attribute to be checked by default for that page type. It seems that the attribute becomes available and is ticked, but it isn't actually set for those pages til it gets 're-ticked' and then saved.)