mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
Merge pull request #333 from assertchris/remove-featured-posts
Removed featured posts
This commit is contained in:
commit
388b868b89
@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
class BlogFeatureExtension extends DataExtension {
|
||||
/**
|
||||
* @config
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private static $excluded_feature_posts = 1;
|
||||
|
||||
/**
|
||||
* @return DataList
|
||||
*/
|
||||
public function getFeaturedBlogPosts() {
|
||||
return BlogPost::get()
|
||||
->filter('ParentID', $this->owner->ID)
|
||||
->filter('IsFeatured', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DataList $posts
|
||||
* @param null|string $context Context for these blog posts (e.g 'rss')
|
||||
*
|
||||
* @return DataList
|
||||
*/
|
||||
public function updateGetBlogPosts(DataList &$posts, $context = null) {
|
||||
if($context === 'rss') {
|
||||
return;
|
||||
}
|
||||
|
||||
$excluded = (int) Config::inst()->get('BlogFeatureExtension', 'excluded_feature_posts');
|
||||
|
||||
if($excluded > 0) {
|
||||
$taken = $this->getFeaturedBlogPosts()->limit($excluded);
|
||||
|
||||
if ($taken->count()) {
|
||||
$posts = $posts->exclude(array('ID' => $taken->getIDList()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
class BlogPostFeatureExtension extends DataExtension {
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $db = array(
|
||||
'IsFeatured' => 'Boolean',
|
||||
);
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*
|
||||
* @param FieldList
|
||||
*/
|
||||
public function updateCMSFields(FieldList $fields) {
|
||||
$sidebar = $fields->fieldByName('blog-admin-sidebar');
|
||||
|
||||
$sidebar->insertBefore('PublishDate', new CheckboxField('IsFeatured', 'Mark as featured post'));
|
||||
}
|
||||
}
|
@ -471,14 +471,12 @@ class Blog extends Page implements PermissionProvider {
|
||||
/**
|
||||
* Return blog posts.
|
||||
*
|
||||
* @param null|string $context Context for these blog posts (e.g 'rss')
|
||||
*
|
||||
* @return DataList of BlogPost objects
|
||||
*/
|
||||
public function getBlogPosts($context = null) {
|
||||
public function getBlogPosts() {
|
||||
$blogPosts = BlogPost::get()->filter('ParentID', $this->ID);
|
||||
|
||||
$this->extend('updateGetBlogPosts', $blogPosts, $context);
|
||||
$this->extend('updateGetBlogPosts', $blogPosts);
|
||||
|
||||
return $blogPosts;
|
||||
}
|
||||
@ -997,7 +995,7 @@ class Blog_Controller extends Page_Controller {
|
||||
*/
|
||||
$dataRecord = $this->dataRecord;
|
||||
|
||||
$this->blogPosts = $dataRecord->getBlogPosts('rss');
|
||||
$this->blogPosts = $dataRecord->getBlogPosts();
|
||||
|
||||
$rss = new RSSFeed($this->blogPosts, $this->Link(), $this->MetaTitle, $this->MetaDescription);
|
||||
|
||||
|
@ -7,7 +7,6 @@
|
||||
* @subpackage blog
|
||||
*
|
||||
* @method Blog Blog()
|
||||
* @method ManyManyList BlogPosts()
|
||||
*
|
||||
* @property string $URLSegment
|
||||
* @property int $BlogID
|
||||
|
@ -7,7 +7,6 @@
|
||||
* @subpackage blog
|
||||
*
|
||||
* @method Blog Blog()
|
||||
* @method ManyManyList BlogPosts
|
||||
*
|
||||
* @property string $Title
|
||||
* @property string $URLSegment
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 66 KiB |
@ -1,38 +0,0 @@
|
||||
# Featured posts
|
||||
|
||||
You can enable featured posts with the following config:
|
||||
|
||||
```yaml
|
||||
---
|
||||
Name: featured-posts-blog-config
|
||||
---
|
||||
Blog:
|
||||
extensions:
|
||||
- BlogFeatureExtension
|
||||
|
||||
BlogPost:
|
||||
extensions:
|
||||
- BlogPostFeatureExtension
|
||||
```
|
||||
|
||||
This will enable a checkbox in the CMS, with which you can feature blog posts:
|
||||
|
||||
![](_images/featured-posts-cms.png)
|
||||
|
||||
By default, the template will show the most recent featured post at the top of the
|
||||
list of posts in a blog. This post will be removed from the normal list of blog posts.
|
||||
You can increase the number of specially-displayed feature posts by modifying the
|
||||
template to show more, and by changing the following config setting:
|
||||
|
||||
```
|
||||
<% if $CanHaveFeaturedBlogPosts && $FeaturedBlogPosts %>
|
||||
<% loop $FeaturedBlogPosts.Limit(10) %>
|
||||
<% include FeaturedPostSummary %>
|
||||
<% end_loop %>
|
||||
<% end_if %>
|
||||
```
|
||||
|
||||
```yaml
|
||||
BlogFeatureExtension:
|
||||
excluded_feature_posts: 10
|
||||
```
|
@ -1,26 +0,0 @@
|
||||
<div class="post-summary featured">
|
||||
<h2>
|
||||
<a href="$Link" title="<%t Blog.ReadMoreAbout "Read more about '{title}'..." title=$Title %>">
|
||||
<% if $MenuTitle %>$MenuTitle
|
||||
<% else %>$Title<% end_if %>
|
||||
</a>
|
||||
</h2>
|
||||
|
||||
<p class="post-image">
|
||||
<a href="$Link" <%t Blog.ReadMoreAbout "Read more about '{title}'..." title=$Title %>>
|
||||
$FeaturedImage.setWidth(795)
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<% if $Summary %>
|
||||
<p>$Summary
|
||||
<% else %>
|
||||
<p>$Excerpt
|
||||
<% end_if %>
|
||||
<a href="$Link">
|
||||
<%t Blog.ReadMoreAbout "Read more about '{title}'..." title=$Title %>
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<% include EntryMeta %>
|
||||
</div>
|
@ -24,21 +24,12 @@
|
||||
|
||||
<div class="content">$Content</div>
|
||||
|
||||
<% if $FeaturedBlogPosts.Exists && $FeaturedBlogPosts.First %>
|
||||
<% with $FeaturedBlogPosts.First %>
|
||||
<% include FeaturedPostSummary %>
|
||||
<% end_with %>
|
||||
<% end_if %>
|
||||
<% if $PaginatedList.Exists %>
|
||||
<% loop $PaginatedList %>
|
||||
<% include PostSummary %>
|
||||
<% end_loop %>
|
||||
<% else %>
|
||||
<% if $FeaturedBlogPosts.Exists %>
|
||||
<p><%t Blog.NoUnfeaturedPosts 'There are no non-featured posts' %></p>
|
||||
<% else %>
|
||||
<p><%t Blog.NoPosts 'There are no posts' %></p>
|
||||
<% end_if %>
|
||||
<p><%t Blog.NoPosts 'There are no posts' %></p>
|
||||
<% end_if %>
|
||||
</article>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user