如何在Orchard中显示博客文章列表?

8
我想要一个简单的小部件放在右侧栏中,它可以显示最近的博客文章列表。除了创建自己的小部件,还有其他简单的方法吗?我在画廊中搜索过,但没有找到。能否有人指点一下我?
编辑:【解决方案】首先我添加了最近的博客文章小部件。然后我创建了一个名为 Parts.Blogs.recentBlogPosts.cshtml 的文件,并将其放置在主题的 Views 目录下。以下是该文件的内容(摘自此处:http://weblogs.asp.net/bleroy/archive/2011/03/27/taking-over-list-rendering-in-orchard.aspx
@using Orchard.ContentManagement;
@{
    IEnumerable<object> blogPosts =
        Model.ContentItems.ContentItems;
}
@if (blogPosts == null || blogPosts.Count() < 1) {
    <p>@T("No posts.")</p>
}
else {
    <ul class="content-items">
    @foreach (dynamic post in blogPosts) {
        string title = post.Title;
        ContentItem item = post.ContentItem;
        <li class="content-item-summary">
            @Html.ItemDisplayLink(title, item)
        </li>
    }
    </ul>
}

感谢您详细说明解决方案。 - awrigley
太好了!我需要以短且符合语言习惯的方式显示发布日期,以及文章摘要。默认的博客文章小部件可以使用,但我的客户不喜欢日期格式...谢谢。 - pomarc
2个回答

4

我正在查看Orchard 1.2,其中有一个“最近博客文章小部件”可供使用 - 您只需要将其添加到您喜欢的层/区域即可。


当我添加那个小部件时,它会给我完整的博客视图。标题、内容等等都在里面。我希望像WordPress一样得到一个链接列表。 - joelnet
你应该能够在主题中覆盖博客文章列表视图。创建一个名为 Views/Orchard.Blogs/Parts.Blogs.RecentBlogPosts.cshtml 的新视图,然后您可以将当前的 @Display(Model.ContentItems) 替换为自己的代码 - 也许是迭代帖子列表并显示标题以及显示帖子链接(或内容摘要)。如果您对此感到不确定,请在这里发布另一个问题,我(或其他人)会更容易回答 :-) - mdm

2

除了编写自己的视图之外,还有两种其他方法可以定制显示内容。

  1. Placement.info 文件。您可以告诉它在给定的contentType和/或DisplayType(摘要或详细信息)下显示哪些字段。您还可以告诉它以什么顺序显示这些字段。

来自thememachine主题中的示例文件。

<Match ContentType="Blog">
  <Match DisplayType="Summary">
    <Place Parts_Blogs_Blog_Description="Content:before"
         Parts_Blogs_Blog_BlogPostCount="Meta:3"/>
  </Match>
</Match>
  1. 一个快速的技巧是使用 CSS 隐藏你不想要的内容。在我发现 placement.info 之前,我曾经用过这个方法来隐藏博客文章的元数据。

顺便说一下,我不知道你是否熟悉设计工具模块,但它非常有用!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接