Jump to:

5537 Posts in 1737 Topics by 1223 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Sitemap with Hierarchical URLs

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1742 Views
  • drewww
    Avatar
    Community Member
    1 Post

    Sitemap with Hierarchical URLs Link to this post

    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.

  • Trent
    Avatar
    Community Member
    2 Posts

    Re: Sitemap with Hierarchical URLs Link to this post

    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.

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: Sitemap with Hierarchical URLs Link to this post

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

  • ram
    Avatar
    Community Member
    19 Posts

    Re: Sitemap with Hierarchical URLs Link to this post

    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

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: Sitemap with Hierarchical URLs Link to this post

    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.

  • ram
    Avatar
    Community Member
    19 Posts
  • feef
    Avatar
    Community Member
    19 Posts

    Re: Sitemap with Hierarchical URLs Link to this post

    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

    1742 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.