问题描述
本来应该很容易,但是我似乎为此感到挣扎.
Silverstripe博客如何对帖子进行排序?我想将特定的博客文章固定在列表的顶部,因此我创建了一个SortOrder字段,并将其值设置为1.尝试按先后按SortOrder和PublishDate进行排序,但似乎始终只能按PublishDate进行排序./p>
即使在博客模型上更改此设置也无济于事:
private static $default_sort = '"PublishDate" IS NULL DESC, "PublishDate" DESC' ;
更新BlogPost
的default_sort
应该有效:
# In your config.yml
BlogPost:
default_sort: 'Sticky DESC, PublishDate DESC'
extensions:
- MyBlogPostExtension
扩展BlogPost以添加Sticky
布尔值(也可以是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
);
}
}
确保您要粘贴的BlogPost
在Sticky
设置为true的情况下发布.
Thought this would be fairly easy but I seem to be struggling with this.
How does the Silverstripe blog sort its posts? I want to pin a specific blog post to the top of the list so I created a SortOrder field and gave it a value of 1. Tried to sort by SortOrder and then by PublishDate but it only seems to sort by PublishDate all the time.
Even changing this on the blog model doesn't do anything:
private static $default_sort = '"PublishDate" IS NULL DESC, "PublishDate" DESC' ;
Updating the default_sort
of BlogPost
should 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.
这篇关于Silverstripe-博客帖子订购的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!