SilverStripe News Module
SilverStripe news is a standalone module which provides content editor features to have news and blog posts in a SilverStripe website., (*1)
Read more at SilverStripers.com blog, (*2)
Installing
User composer to install, (*3)
composer require silverstripers/silverstripe-news dev-master
, (*4)
Features
- Tags
- Categories
- Archives
- Different Types of news posts for different purposes
- Use the powerful model admin to manage news
- robust search form
- friendly urls for tags and categories
- Force editing news from the model admin, and doesnt load news pages on to the site tree.
Configs
All the configuration options are added on to Site Config, (*5)
go to SiteConfig from the laft navigation panel and to, (*6)
Settings -> News tab, (*7)
Codes
Add tags to a page
add the following code to your Page.ss file or any other template file which renders contents of a Page., (*8)
<% if $BlogTags %>
<ul>
<% loop $BlogTags %>
<li><a href='{$Link}'>{$Tag} ({$Count})</a></li>
<% end_loop %>
</ul>
<% end_if %>
Add blog archive to a page
the module allows you to chose that format of archive you want to use, this can be configured in the Site Config.
the options are, (*9)
- Year
- Year, Full Month (2015, April)
- Year, Month Number (2015, 04)
- Abbreviated Month Name (Jan, Feb, Mar, etc..)
welcome to add more options for these and submit pull requests, (*10)
<% if $BlogArchives %>
<ul>
<% loop $BlogArchives %>
<li><a href='{$Link}'>{$Archive}</a></li>
<% end_loop %>
</ul>
<% end_if %>
Categories
to show the news categories made in the CMS use, (*11)
<% if $NewsCategories %>
<ul>
<% loop $NewsCategories %>
<li><a href='{$Link}'>{$Title}</a></li>
<% end_loop %>
</ul>
<% end_if %>
Show news on news index
to show news items on your news index use the following code or similar., (*12)
<% if $Items %>
<ul class="news-list">
<% loop $Items %>
<li class="news-item">
<h2>{$Title}</h2>
<time datetime="{$DateTime.Format('Y-m-d')}">{$DateTime.Format('F d, Y')}</time>
<% if $Summary %>
$Summary
<% else %>
{$Content.FirstSentence}
<% end_if %>
<a class="readMore" href="{$Link}">read more…</a>
</li>
<% end_loop %>
</ul>
<% if $Items.MoreThanOnePage %>
<div class="pagination">
<ul>
<% if $Items.NotFirstPage %>
<li>
<a class="prev" href="{$Items.PrevLink}"><span class="arrow-left"></span></a>
</li>
<% end_if %>
<% loop $Items.Pages %>
<li <% if $CurrentBool %>class="active"<% end_if %>>
<% if $Link %>
<a href="{$Link}">{$PageNum}</a>
<% else %>
…
<% end_if %>
</li>
<% end_loop %>
<% if $Items.NotLastPage %>
<li>
<a class="next" href="{$Items.NextLink}"><span class="arrow-right"></span></a>
</li>
<% end_if %>
</ul>
</div>
<% end_if %>
<% end_if %>
if you want to take the first news articles out of this list, may be on to a hero panel you can do that by passing an offset to the Items functions, (*13)
the function call would be $Items(1)
if you dont want the first item to be returned on to the list., (*14)