Source of file BlogRecentPostsWidget.php
Size: 1,078 Bytes - Last Modified: 2021-12-23T10:04:17+00:00
/var/www/docs.ssmods.com/process/src/code/widgets/BlogRecentPostsWidget.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 | <?php if(class_exists("Widget")) { class BlogRecentPostsWidget extends Widget { private static $title = "Recent Posts"; private static $cmsTitle = "Recent Posts"; private static $description = "Displays a list of recent blog posts."; private static $db = array( "NumberOfPosts" => "Int", ); private static $has_one = array( "Blog" => "Blog", ); public function getCMSFields() { $fields = FieldList::create(); $fields->merge(array( DropdownField::create("BlogID", _t("BlogRecentPostsWidget.Blog", "Blog"), Blog::get()->map()), NumericField::create("NumberOfPosts", _t("BlogRecentPostsWidget.NumberOfPosts", "Number of Posts")) )); $this->extend("updateCMSFields", $fields); return $fields; } public function getPosts() { $blog = $this->Blog(); if($blog) { return $blog->getBlogPosts() ->sort("PublishDate DESC") ->limit($this->NumberOfPosts); } return array(); } } class BlogRecentPostsWidget_Controller extends Widget_Controller { } } |