Making ‘News’ Page with Addons in SilverStripe CMS Part 1

To show news on frontpage, you need to make the News pagetype and holder for it. In this and the next post, I’m going to tell you how to make the News pagetype and add some addons to the pagetype.

  1. Make file ArticlePage.php to mysite/code/ folder with code:
    <?php
    class ArticlePage extends Page {
        static $db = array(
           'Date' => 'Date',
           'Author' => 'Text',
        );
    function getCMSFields() {
        $fields = parent::getCMSFields();
        $fields->addFieldToTab('Root.Content.Main', $dateField = new DateField('Date','Article Date (for example: 20/12/2010)'), 'Content');
        $dateField->setConfig('showcalendar', true);
        $dateField->setConfig('dateformat', 'dd/MM/YYYY');
        $fields->addFieldToTab('Root.Content.Main', new TextField('Author','Author Name'), 'Content');
        return $fields;
    }
    }
    class ArticlePage_Controller extends Page_Controller {
    }
    ?>
  2. Make the holder called ArticleHolder.php to folder mysite/code/ with this code:
    <?php
    class ArticleHolder extends Page {
        static $db = array(
        );
        static $has_one = array(
        );
        static $allowed_children = array('ArticlePage');
    }
    class ArticleHolder_Controller extends Page_Controller {
    }
    ?>
  3. Make ArticlePage.ss to themes/yourtheme/templates/Layout/ folder using code:
    <div class="typography">
    	<% if Menu(2) %>
    		<% include SideBar %>
    		<div id="Content">
    	<% end_if %>
    	<% if Level(2) %>
    	  	<% include BreadCrumbs %>
    	<% end_if %>
    		<h2>$Title</h2>
    		$Content
    	<div class="newsDetails">
            	Posted on $Date.Nice by $Author
        	</div>
    	<% if Menu(2) %>
    		</div>
    	<% end_if %>
    </div>
  4. Make ArticleHolder.ss to themes/yourtheme/templates/Layout/ folder using code:
    <div class="typography">
    	<% if Menu(2) %>
    		<% include SideBar %>
    		<div id="Content">
    	<% end_if %>
    	<% if Level(2) %>
    	  	<% include BreadCrumbs %>
    	<% end_if %>
    		<h2>$Title</h2>
    		$Content
    		<ul id="NewsList">
    		<% control Children %>
    		<li class="newsDateTitle"><a href="$Link" title="Read more on &quot;{$Title}&quot;">$Title</a></li>
    		<li class="newsDateTitle">$Date.Nice</li>
    		<li class="newsSummary">$Content.FirstParagraph <a href="$Link" title="Read more on &quot;{$Title}&quot;">Read more &gt;&gt;</a></li>
    		<% end_control %>
    		</ul>
        	</div>
    	<% if Menu(2) %>
    		</div>
    	<% end_if %>
    </div>
  5. Rebuild datababse using www.yousitename.com/dev/build?flush=1

Looking for quality SilverStripe Web Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , , , , , , , , , | Posted under SilverStripe CMS | RSS 2.0

Author Spotlight

Teet Bergmann

Teet Bergmann

I'm a freelance web designer from Estonia. Mostly doing sites using Silverstripe, magento, prestashop, wordpress.

Leave a Reply

Your email address will not be published. Required fields are marked *


4 + 5 =

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>