Jump to:

23368 Posts in 18143 Topics by 2863 members

General Questions

SilverStripe Forums » General Questions » [Solved] Narrowing the Site Map

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 886 Views
  • jfusco
    Avatar
    Community Member
    52 Posts

    [Solved] Narrowing the Site Map Link to this post

    I want to create a site map that is, essentially, a subset of the actual site map. That is, I want to have a regular site map but I also want to create a site map that only lists article pages.

    I searched the forums and thought I had found the answer. I copied sitemap.php into articlemap.php and changed the following:

    class ArticleMap extends Page {
    ...
    function ArticleMap() {
    $rootLevel = DataObject::get("ArticlePage", "ParentID = 0");
    ...
    <ul id="articlemap-list">';
    ...

    I rebuilt the database and added $ArticleMap to ..\layout\page.ss right underneath $SiteMap. The site map works fine but the article map comes up empty. I am not a programmer but can usually figure out what scripts and other code is trying to do. Should I have left the function name as SiteMap? What did I miss?

    I would also like to know if, once I get it working, it is possible alphabetize the output. Because of the way I have the article holders set up, it will (to the best I can figure) create several blocks of alphabetized lists.

    My site map is at http://www.unclebubby.com/wavs2/site-map/ if you want to take a look.

    Thanks,
    Joe

  • jfusco
    Avatar
    Community Member
    52 Posts

    Re: [Solved] Narrowing the Site Map Link to this post

    Something I didn't previously mention was that my base file is the sitemap.php file from tutorial 6.

    I've got the listing part figured out. First, I didn't understand the relationship between $rootLevel = DataObject... and ...->makeList($rootLevel). I changed both of those variables to $articlePages and got exactly what I asked for... the one and only article page I have on the root level.

    Since I wanted all article pages, I deleted the "ParentID = 0" from the get statement and that retrieved all of the article pages.

    Now I just need to figure out how to alphabetize the list (it's a complete jumble). I also would like to see it in columns but I figure that's a CSS issue? I think I may open a new thread on each or both of those.

  • Terminator4
    Avatar
    Community Member
    81 Posts

    Re: [Solved] Narrowing the Site Map Link to this post

    sounds like you haven't put $ArticleMap into your template page (YourPage.ss)

    Have a look at how the Search page was done @ http://doc.silverstripe.com/doku.php?id=tutorial:4-site-search&s=template

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: [Solved] Narrowing the Site Map Link to this post

    For sorting, remember the old:

    $records = DataObject::get($obj, $filter, $sort, $join, $limit);

    So to alphabetize, you should be able to do something like:

    ...
    function ArticleMap() {
    $rootLevel = DataObject::get("ArticlePage", "", "Title DESC");
    ...

    As for columns, that's going to be a bit trickier. CSS horizontal column is a bit of a holy grail, so you might have to create a couple of functions, each returning a sub-set of results. You can then put each sub-set in it's own column.

  • jfusco
    Avatar
    Community Member
    52 Posts

    Re: [Solved] Narrowing the Site Map Link to this post

    One of my initial struggles was splitting up the results. I thought the last parameter was "starting record #, Ending record #" but it's actually "starting record #, # of records to display." That got the records split up evenly among the sections (see ArticleMap.php). I also finally stumbled upon the DataObject::get syntax you mentioned and got them sorted. For the columns, I opted for an HTML table. It's old school, but it works (see ArticleMap.ss).

    This code can easily be adapted to as many columns as you have room for. Here's what I ended up with.
    ArticleMap.php

    <?php

    class ArticleMap extends Page {
       static $db = array(
       );
       static $has_one = array(
       );
    }

    class ArticleMap_Controller extends Page_Controller {

       function Articles() {
    return DataObject::get("ArticlePage");
    }

    function Row1() {
             $Begin = 0;
             $End = ceil(($this->Articles()->Count()) / 3);
             return DataObject::get("ArticlePage", "", "Title", "", "$Begin, $End");
    }

    function Row2() {
             $Begin = ceil(($this->Articles()->Count()) / 3);
             return DataObject::get("ArticlePage", "", "Title", "", "$Begin, $Begin");
    }

    function Row3() {
    $Total = ($this->Articles()->Count()) ;
    $Part = ceil(($Total / 3));
    $Begin = ceil(($Part * 2));
             return DataObject::get("ArticlePage", "", "Title", "", "$Begin, $Total");
    }
    }

    ?>


    ArticleMap.ss

    <table>
    <tr>
    <td>
    <div class="col float-left">
       <ul>
    <% control Row1 %>
          <li><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode">$MenuTitle</a>      </li>
        <% end_control %>
    </ul>
    </div>
    </td>

    <td>
    <div class="col float-left">
       <ul>
          <% control Row2 %>
          <li><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode">$MenuTitle</a>      </li>
          <% end_control %>
       </ul>
    </div>
    </td>

    <td>
    <div class="col float-left">
       <ul>
          <% control Row3 %>
          <li><a href="$Link" title="Go to the $Title.XML page" class="$LinkingMode">$MenuTitle</a>      </li>
          <% end_control %>
       </ul>
    </div>
    </td>
    </tr>
    </table>

    886 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.