Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Customising the CMS /

Sitemap with Hierarchical URLs


Reply


7 Posts   1775 Views

Avatar
drewww

Community Member, 1 Post

17 March 2010 at 5:12pm

Hi all,

I'm trying to work out how to update the sitemap code as given in the Wiki (http://doc.silverstripe.org/doku.php?id=tutorial:site-map) to work with the new hierarchical URLs in 2.4 beta.

Using $page->URLSegment gives just the final segment (as expected) but how do we go about getting the full URL? Using $page->Link doesn't work from the controller.

Cheers.

Avatar
Trent

Community Member, 2 Posts

28 April 2010 at 6:53am

I am using the SiteMapModule, so it will be a little different for you, but in the module, there is a makeChildList function for creating the nested links. I passed an additional parameter to this function for the parent page's url, which I called $parentURL which I amended to the beginning of the href tag as shown below:

private function makeList($pages) {
$output = "";
if(count($pages)) {
$output = '
<ul id="sitemap-list">';
foreach($pages as $page) {
if(!($page instanceof ErrorPage) && $page->ShowInMenus && $page->Title != $this->Title){
$output .= '
<li><a href="'.$page->URLSegment.'" title="Go to the '.Convert::raw2xml($page->Title).' page">'.Convert::raw2xml($page->MenuTitle).'</a>';
$whereStatement = "ParentID = ".$page->ID;
//$childPages = new DataObjectSet();
$childPages = DataObject::get("Page", $whereStatement);
$output .= $this->makeChildList($childPages, $page->URLSegment);
$output .= '
</li>';
}
}
$output .= '
</ul>';
}
return $output;
}


private function makeChildList($pages, $parentURL) {
      $output = "";
      if(count($pages)) {
            $output = '
               <ul>';
         foreach($pages as $page) {

            /* if selected, check if user has permission to view page and skip rendering it if they don't have permission. */
            if (self::$siteMapPermissionCheck) {
               if (!$page->canView()) {
                  continue;
               }
            }
            
            $nestedURL = $parentURL != NULL ? $parentURL.'/'.$page->URLSegment : $page->URLSegment;
   
            $output .= '
                  <li><a href="'.$nestedURL.'" title="Go to the '.Convert::raw2xml($page->Title).' page">'.Convert::raw2xml($page->MenuTitle).'</a>';
            $whereStatement = "ParentID = ".$page->ID." AND ClassName NOT IN(".self::$siteMapSkipPageTypes.")";
            $childPages = DataObject::get("Page", $whereStatement);
            if($childPages) {
               $output .= $this->makeChildList($childPages, $nestedURL);
            }
            $output .= '</li>';
         }
         $output .= '
               </ul>
            ';
      }
      return $output;
   }

There is probably a better way with 2.4, but this works well for the meantime.

Avatar
ajshort

Community Member, 244 Posts

28 April 2010 at 10:03am

$page->Link() is a method, that's why it wasn't working.

Avatar
ram

Community Member, 19 Posts

6 May 2010 at 11:00pm

Hi ajshort,

I have successfully upgraded to 2.4.0. but I need some questions about Hierarchical URLs.

silverstripe cms used for our product site. current site url used for SEO terms.

we give rewrite url in httaccess or web.config, when we have few redirect. But we are having more urls in our product site. If I change the site url it will affect more visitors to our product sites.

Is there any possibility to on-off the Hierarchical URLs?

how do I fix when I upgrade to 2.4.0 or is it better to retain the old version.

Regards,
Ram
http://www.agriya.com, http://www.rayzz.net, http://www.isocial.in, http://www.anova.tv, http://www.markit.me

Avatar
ajshort

Community Member, 244 Posts

6 May 2010 at 11:19pm

If you are upgrading a site just don't add "SiteTree::enable_nested_urls()" to your config file and the URLs will stay the same as your old 2.3 site. Keep in mind that users are automatically redirected from old non-nested URLs to new nested URLs if you do enable them.

Avatar
ram

Community Member, 19 Posts

7 May 2010 at 12:22am

Thanks ajshort

now working fine.

Regards,
Ram
http://www.agriya.com, http://www.rayzz.net, http://www.isocial.in, http://www.anova.tv, http://www.markit.me

Avatar
feef

Community Member, 19 Posts

5 June 2010 at 11:37pm

I've got my sitemap working, but is there any way for it to include the image galleries within a gallery page?
For example, the sitemap includes "bikes" which is a gallery page, but I would also like it to include the galleries titles within that.

I suspect that, since this will probably require db queries to the image gallery data, that it might not be a trivial task?

Any pointers on where to start looking? My php is rusty at best, but I know my way around MySQL.

tia

a