diff --git a/code/extensions/BlogFeatureExtension.php b/code/extensions/BlogFeatureExtension.php new file mode 100644 index 0000000..cbd076f --- /dev/null +++ b/code/extensions/BlogFeatureExtension.php @@ -0,0 +1,41 @@ +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())); + } + } + } +} diff --git a/code/extensions/BlogPostFeatureExtension.php b/code/extensions/BlogPostFeatureExtension.php new file mode 100644 index 0000000..99d1593 --- /dev/null +++ b/code/extensions/BlogPostFeatureExtension.php @@ -0,0 +1,21 @@ + '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')); + } +} diff --git a/code/model/Blog.php b/code/model/Blog.php index ceea732..e3da896 100644 --- a/code/model/Blog.php +++ b/code/model/Blog.php @@ -362,7 +362,7 @@ class Blog extends Page implements PermissionProvider { if($this->config()->grant_user_access) { $list = Member::get(); $this->extend('updateCandidateUsers', $list); - return $list; + return $list; } else { return Permission::get_members_by_permission( $this->config()->grant_user_permission @@ -471,12 +471,14 @@ 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() { + public function getBlogPosts($context = null) { $blogPosts = BlogPost::get()->filter('ParentID', $this->ID); - $this->extend('updateGetBlogPosts', $blogPosts); + $this->extend('updateGetBlogPosts', $blogPosts, $context); return $blogPosts; } @@ -964,6 +966,7 @@ class Blog_Controller extends Page_Controller { */ public function PaginatedList() { $allPosts = $this->blogPosts ?: new ArrayList(); + $posts = new PaginatedList($allPosts); // Set appropriate page size @@ -994,7 +997,7 @@ class Blog_Controller extends Page_Controller { */ $dataRecord = $this->dataRecord; - $this->blogPosts = $dataRecord->getBlogPosts(); + $this->blogPosts = $dataRecord->getBlogPosts('rss'); $rss = new RSSFeed($this->blogPosts, $this->Link(), $this->MetaTitle, $this->MetaDescription); diff --git a/code/model/BlogPost.php b/code/model/BlogPost.php index 1b46817..84ca8f2 100644 --- a/code/model/BlogPost.php +++ b/code/model/BlogPost.php @@ -173,7 +173,7 @@ class BlogPost extends Page { $self =& $this; $this->beforeUpdateCMSFields(function ($fields) use ($self) { - $uploadField = UploadField::create('FeaturedImage', _t('BlogPost.FeaturedImage', 'Featured Image')); + $uploadField = UploadField::create('FeaturedImage', _t('BlogPost.FeaturedImage', 'Banner Image')); $uploadField->getValidator()->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif')); /** @@ -272,6 +272,8 @@ class BlogPost extends Page { $authorNames )->setTitle('Post Options'); + $options->setName('blog-admin-sidebar'); + $fields->insertBefore($options, 'Root'); }); @@ -658,7 +660,7 @@ class BlogPost extends Page { public function fieldLabels($includeRelations = true) { $labels = parent::fieldLabels($includeRelations); - $labels['Title'] = _t('BlogPost.PageTitleLabel', "Post Title"); + $labels['Title'] = _t('BlogPost.PageTitleLabel', 'Post Title'); return $labels; } diff --git a/docs/en/_images/featured-posts-cms.png b/docs/en/_images/featured-posts-cms.png new file mode 100644 index 0000000..fa3b5d0 Binary files /dev/null and b/docs/en/_images/featured-posts-cms.png differ diff --git a/docs/en/featured-posts.md b/docs/en/featured-posts.md new file mode 100644 index 0000000..e7bea76 --- /dev/null +++ b/docs/en/featured-posts.md @@ -0,0 +1,38 @@ +# 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 +``` diff --git a/lang/en.yml b/lang/en.yml index 0ffb190..62e7268 100755 --- a/lang/en.yml +++ b/lang/en.yml @@ -69,7 +69,7 @@ en: CUSTOMSUMMARY: 'Add A Custom Summary' Categories: Categories DESCRIPTION: 'Generic content page' - FeaturedImage: 'Featured Image' + FeaturedImage: 'Banner Image' PLURALNAME: 'Base Pages' PageTitleLabel: 'Post Title' PublishDate: 'Publish Date' diff --git a/templates/BlogAdminSidebar_holder.ss b/templates/BlogAdminSidebar_holder.ss index b1dbf7b..52cbf69 100644 --- a/templates/BlogAdminSidebar_holder.ss +++ b/templates/BlogAdminSidebar_holder.ss @@ -1,20 +1,20 @@
-
-
-

$Title

+ data-expandOnClick="true" + data-layout-type="border" + id="blog-admin-sidebar"> +
+
+

$Title

<% loop $Children %> $FieldHolder <% end_loop %> -
-
-
-

$Title

-
-
- « - » -
+
+
+
+

$Title

+
+
+ « + » +
diff --git a/templates/Includes/BlogSideBar.ss b/templates/Includes/BlogSideBar.ss index 840df55..d2419a3 100644 --- a/templates/Includes/BlogSideBar.ss +++ b/templates/Includes/BlogSideBar.ss @@ -1,5 +1,5 @@ <% if $SideBarView %> -
- $SideBarView -
+
+ $SideBarView +
<% end_if %> diff --git a/templates/Includes/FeaturedPostSummary.ss b/templates/Includes/FeaturedPostSummary.ss new file mode 100644 index 0000000..7ca2725 --- /dev/null +++ b/templates/Includes/FeaturedPostSummary.ss @@ -0,0 +1,26 @@ +
+

+ "> + <% if $MenuTitle %>$MenuTitle + <% else %>$Title<% end_if %> + +

+ +

+ > + $FeaturedImage.setWidth(795) + +

+ + <% if $Summary %> +

$Summary + <% else %> +

$Excerpt + <% end_if %> + + <%t Blog.ReadMoreAbout "Read more about '{title}'..." title=$Title %> + +

+ + <% include EntryMeta %> +
diff --git a/templates/Includes/MemberDetails.ss b/templates/Includes/MemberDetails.ss index afa7dd1..b968786 100644 --- a/templates/Includes/MemberDetails.ss +++ b/templates/Includes/MemberDetails.ss @@ -1,13 +1,13 @@
-

$CurrentProfile.FirstName $CurrentProfile.Surname

-
- <% if $CurrentProfile.BlogProfileImage %> -
- $CurrentProfile.BlogProfileImage.setWidth(180) -
- <% end_if %> -
-

$CurrentProfile.BlogProfileSummary

-
-
+

$CurrentProfile.FirstName $CurrentProfile.Surname

+
+ <% if $CurrentProfile.BlogProfileImage %> +
+ $CurrentProfile.BlogProfileImage.setWidth(180) +
+ <% end_if %> +
+

$CurrentProfile.BlogProfileSummary

+
+
diff --git a/templates/Includes/Pagination.ss b/templates/Includes/Pagination.ss index 1a20c7e..e704dd3 100644 --- a/templates/Includes/Pagination.ss +++ b/templates/Includes/Pagination.ss @@ -1,25 +1,25 @@ <%-- NOTE: Before including this, you will need to wrap the include in a with block --%> <% if $MoreThanOnePage %> -

- <% if $NotFirstPage %> - - <% end_if %> - - <% loop $Pages %> - <% if $CurrentBool %> - $PageNum - <% else %> - <% if $Link %> - $PageNum - <% else %> - ... - <% end_if %> - <% end_if %> - <% end_loop %> - - <% if $NotLastPage %> - - <% end_if %> -

+

+ <% if $NotFirstPage %> + + <% end_if %> + + <% loop $Pages %> + <% if $CurrentBool %> + $PageNum + <% else %> + <% if $Link %> + $PageNum + <% else %> + ... + <% end_if %> + <% end_if %> + <% end_loop %> + + <% if $NotLastPage %> + + <% end_if %> +

<% end_if %> diff --git a/templates/Layout/Blog.ss b/templates/Layout/Blog.ss index d858857..5cccf67 100644 --- a/templates/Layout/Blog.ss +++ b/templates/Layout/Blog.ss @@ -2,41 +2,50 @@
-
-

- <% if $ArchiveYear %> - <%t Blog.Archive "Archive" %>: - <% if $ArchiveDay %> - $ArchiveDate.Nice - <% else_if $ArchiveMonth %> - $ArchiveDate.format("F, Y") - <% else %> - $ArchiveDate.format("Y") - <% end_if %> - <% else_if $CurrentTag %> - <%t Blog.Tag "Tag" %>: $CurrentTag.Title - <% else_if $CurrentCategory %> - <%t Blog.Category "Category" %>: $CurrentCategory.Title - <% else %> - $Title - <% end_if %> -

- -
$Content
- - <% if $PaginatedList.Exists %> - <% loop $PaginatedList %> - <% include PostSummary %> - <% end_loop %> - <% else %> -

<%t Blog.NoPosts "There are no posts" %>

- <% end_if %> -
- - $Form - $CommentsForm - - <% with $PaginatedList %> +
+

+ <% if $ArchiveYear %> + <%t Blog.Archive 'Archive' %>: + <% if $ArchiveDay %> + $ArchiveDate.Nice + <% else_if $ArchiveMonth %> + $ArchiveDate.format('F, Y') + <% else %> + $ArchiveDate.format('Y') + <% end_if %> + <% else_if $CurrentTag %> + <%t Blog.Tag 'Tag' %>: $CurrentTag.Title + <% else_if $CurrentCategory %> + <%t Blog.Category 'Category' %>: $CurrentCategory.Title + <% else %> + $Title + <% end_if %> +

+ +
$Content
+ + <% 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 %> +

<%t Blog.NoUnfeaturedPosts 'There are no non-featured posts' %>

+ <% else %> +

<%t Blog.NoPosts 'There are no posts' %>

+ <% end_if %> + <% end_if %> +
+ + $Form + $CommentsForm + + <% with $PaginatedList %> <% include Pagination %> <% end_with %>
diff --git a/templates/Layout/BlogPost.ss b/templates/Layout/BlogPost.ss index 7321487..f3839dc 100644 --- a/templates/Layout/BlogPost.ss +++ b/templates/Layout/BlogPost.ss @@ -3,17 +3,17 @@

$Title

- - <% if $FeaturedImage %> + + <% if $FeaturedImage %>

$FeaturedImage.setWidth(795)

<% end_if %> - +
$Content
<% include EntryMeta %>
- - $Form + + $Form $CommentsForm
diff --git a/templates/Layout/Blog_profile.ss b/templates/Layout/Blog_profile.ss index 2f64175..78f65dc 100644 --- a/templates/Layout/Blog_profile.ss +++ b/templates/Layout/Blog_profile.ss @@ -2,22 +2,22 @@
- <% include MemberDetails %> + <% include MemberDetails %> - <% if $PaginatedList.Exists %> -

Posts by $CurrentProfile.FirstName $CurrentProfile.Surname for $Title:

- <% loop $PaginatedList %> - <% include PostSummary %> - <% end_loop %> - <% end_if %> - - $Form - $CommentsForm + <% if $PaginatedList.Exists %> +

Posts by $CurrentProfile.FirstName $CurrentProfile.Surname for $Title:

+ <% loop $PaginatedList %> + <% include PostSummary %> + <% end_loop %> + <% end_if %> - <% with $PaginatedList %> - <% include Pagination %> - <% end_with %> + $Form + $CommentsForm + + <% with $PaginatedList %> + <% include Pagination %> + <% end_with %>
-<% include BlogSideBar %> \ No newline at end of file +<% include BlogSideBar %>