diff --git a/Block/Index.php b/Block/Index.php index e9f20046..c2a897a1 100644 --- a/Block/Index.php +++ b/Block/Index.php @@ -48,6 +48,7 @@ protected function _preparePostCollection() \Magefan\Blog\Helper\Config::XML_PATH_HOMEPAGE_DISPLAY_MODE, ScopeInterface::SCOPE_STORE ); + /* If featured posts enabled */ if ($displayMode == 1) { $postIds = $this->_scopeConfig->getValue( @@ -55,6 +56,8 @@ protected function _preparePostCollection() ScopeInterface::SCOPE_STORE ); $this->_postCollection->addPostsFilter($postIds); + } else { + $this->_postCollection->addRecentFilter(); } } diff --git a/Block/Sidebar/Recent.php b/Block/Sidebar/Recent.php index e7c00b74..8fb57404 100755 --- a/Block/Sidebar/Recent.php +++ b/Block/Sidebar/Recent.php @@ -34,6 +34,17 @@ public function _construct() return parent::_construct(); } + /* + * Prepare posts collection + * + * @return void + */ + protected function _preparePostCollection() + { + parent::_preparePostCollection(); + $this->_postCollection->addRecentFilter(); + } + /** * Retrieve block identities * @return array diff --git a/Block/Widget/Recent.php b/Block/Widget/Recent.php index b3471b29..926125b5 100755 --- a/Block/Widget/Recent.php +++ b/Block/Widget/Recent.php @@ -91,6 +91,7 @@ protected function _preparePostCollection() parent::_preparePostCollection(); + $this->_postCollection->addRecentFilter(); if ($category = $this->getCategory()) { $this->_postCollection->addCategoryFilter($category); } diff --git a/Model/ResourceModel/Post/Collection.php b/Model/ResourceModel/Post/Collection.php index dc2ae086..2545cdfd 100755 --- a/Model/ResourceModel/Post/Collection.php +++ b/Model/ResourceModel/Post/Collection.php @@ -130,7 +130,16 @@ public function addStoreFilter($store, $withAdmin = true) } return $this; } - + + /** + * Add "include in recent" filter to collection + * @return $this + */ + public function addRecentFilter() + { + return $this->addFieldToFilter('include_in_recent', 1); + } + /** * Add posts filter to collection * @param array|int|string $category diff --git a/Setup/UpgradeSchema.php b/Setup/UpgradeSchema.php index a037f471..28ba80c2 100644 --- a/Setup/UpgradeSchema.php +++ b/Setup/UpgradeSchema.php @@ -63,7 +63,7 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con } if (version_compare($version, '2.2.0') < 0) { - /* Add author field to posts tabel */ + /* Add author field to posts table */ $connection->addColumn( $setup->getTable('magefan_blog_post'), 'author_id', @@ -84,7 +84,7 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con if (version_compare($version, '2.2.5') < 0) { - /* Add layout field to posts and category tabels */ + /* Add layout field to posts and category table */ foreach (['magefan_blog_post', 'magefan_blog_category'] as $table) { $table = $setup->getTable($table); $connection->addColumn( @@ -165,7 +165,7 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con } if (version_compare($version, '2.3.0') < 0) { - /* Add meta title field to posts tabel */ + /* Add meta title field to posts table */ $connection->addColumn( $setup->getTable('magefan_blog_post'), 'meta_title', @@ -178,7 +178,7 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con ] ); - /* Add og tags fields to post tabel */ + /* Add og tags fields to post table */ foreach (['type', 'img', 'description', 'title'] as $type) { $connection->addColumn( $setup->getTable('magefan_blog_post'), @@ -193,7 +193,7 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con ); } - /* Add meta title field to category tabel */ + /* Add meta title field to category table */ $connection->addColumn( $setup->getTable('magefan_blog_category'), 'meta_title', @@ -452,7 +452,7 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con } if (version_compare($version, '2.6.2') < 0) { - /* Add include in menu field into categories tabel */ + /* Add include in menu field into categories table */ $connection->addColumn( $setup->getTable('magefan_blog_category'), 'include_in_menu', @@ -473,7 +473,7 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con } if (version_compare($version, '2.6.3') < 0) { - /* Add display mode field into category tabel */ + /* Add display mode field into category table */ $connection->addColumn( $setup->getTable('magefan_blog_category'), 'display_mode', @@ -488,6 +488,23 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con ); } + + if (version_compare($version, '2.6.3.1') < 0) { + /* Add include in recent posts into post table */ + $connection->addColumn( + $setup->getTable('magefan_blog_post'), + 'include_in_recent', + [ + 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, + null, + 'nullable' => false, + 'default' => '1', + 'comment' => 'Include in Recent Posts', + 'after' => 'is_active' + ] + ); + } + $setup->endSetup(); } } diff --git a/etc/module.xml b/etc/module.xml index 5b9805db..989f7940 100755 --- a/etc/module.xml +++ b/etc/module.xml @@ -8,7 +8,7 @@ */ --> - + diff --git a/view/adminhtml/ui_component/blog_post_form.xml b/view/adminhtml/ui_component/blog_post_form.xml index 8a7eaeac..48bf7a04 100644 --- a/view/adminhtml/ui_component/blog_post_form.xml +++ b/view/adminhtml/ui_component/blog_post_form.xml @@ -325,6 +325,24 @@ + + + + boolean + Include in Recent Posts + checkbox + toggle + post + 60 + include_in_recent + + 1 + 0 + + 1 + + +