Silverstripe - 博客文章订购

时间:2017-04-06 06:59:21

标签: sorting blogs silverstripe

认为这很容易,但我似乎在努力解决这个问题。

Silverstripe博客如何对其帖子进行排序?我想将一个特定的博客帖子固定到列表的顶部,这样我创建了一个SortOrder字段,并给它一个值1.尝试按SortOrder排序,然后按PublishDate排序,但它似乎只是按PublishDate排序。< / p>

即使在博客模型上更改此内容也无效:

private static $default_sort = '"PublishDate" IS NULL DESC, "PublishDate" DESC' ;

2 个答案:

答案 0 :(得分:5)

Updating the default_sort of BlogPostshould work:

# In your config.yml
BlogPost:
  default_sort: 'Sticky DESC, PublishDate DESC'
  extensions:
    - MyBlogPostExtension

Extend BlogPost to add a Sticky boolean (this could also be an Int):

class MyBlogPostExtension extends DataExtension
{

    private static $db = [
        'Sticky' => 'Boolean'
    ];

    public function updateCMSFields(FieldList $fields)
    {
        $stickyField = CheckboxField::create(
            'Sticky',
            'Sticky this blogpost'
        );

        $fields->addFieldToTab(
            'Root.Main',
            $stickyField
        );
    }

}

Make sure that the BlogPost you want stickied is published with Sticky set to true.

答案 1 :(得分:1)

我在博客,排序&amp;伐木工人(GridField中的帖子不是Sitetree)。我使用heyday / silverstripe-gridfieldversionedorderablerows让它可以手动排序。

Injector:
  GridFieldConfig_BlogPost:
    class: GridFieldConfig_MyBlogPost

<?php
class GridFieldConfig_MyBlogPost extends GridFieldConfig_BlogPost
{
    public function __construct($itemsPerPage = null)
    {
        parent::__construct($itemsPerPage);
        $this->addComponent(new GridFieldVersionedOrderableRows('Sort'));
        $this->getComponentByType("GridFieldPaginator")->setItemsPerPage(100);
        $this->getComponentByType("GridFieldDataColumns")->setDisplayFields(array(
            "BlogThumbnail" => "Thumbnail",
            "Title" => "Title"
        ));
    }
}

我在博客的DataExtension上创建了自己的PaginatedListSorted,但你很可能只能按照每个yml的Janne Klouman建议排序。