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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

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

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

[Solved] Narrowing the Site Map


Go to End


5 Posts   1776 Views

Avatar
jfusco

Community Member, 53 Posts

22 January 2009 at 4:49pm

Edited: 28/01/2009 10:49am

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

Avatar
jfusco

Community Member, 53 Posts

23 January 2009 at 4:45am

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.

Avatar
Terminator4

Community Member, 81 Posts

28 January 2009 at 6:18am

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

Avatar
Hamish

Community Member, 712 Posts

28 January 2009 at 9:20am

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.

Avatar
jfusco

Community Member, 53 Posts

28 January 2009 at 10:55am

Edited: 28/01/2009 10:57am

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>