How can I display a list of blog posts in Orchard?
Asked Answered
L

2

8

I want a simple widget for my right side column that can display a list of recent blog posts.

is there an easy way to do this other than creating my own widget? i've searched the gallery for one and wasn't able to find one.

can someone point me in the right direction?

EDIT: [SOLUTION]

First I added the Recent Blog Posts widget. Then I created a file Parts.Blogs.recentBlogPosts.cshtml and placed it under the Views directory of my theme. Here's the contents of the file (taken from here: 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>
}
Luo answered 18/7, 2011 at 1:52 Comment(2)
Thanks for detailing the solution.Whitmore
nice! I'd need to show the published date too, in a short, locale aware way, and the summary of the post body. (the default blog post widget is ok, but my customer doesn't like the date format...) thanks.Seay
K
4

I'm looking at Orchard 1.2 and there is a 'Recent Blog Posts Widget' available to you - all you need to do is add it to your preferred layer/zone.

Kauri answered 18/7, 2011 at 8:7 Comment(2)
when i add that widget, it gives me the full blog view. title, content, etc. I'd like a list of links, kind of like the way wordpress works.Luo
You should be able to override the blog post list view in your theme. Create a new view called Views/Orchard.Blogs/Parts.Blogs.RecentBlogPosts.cshtml and from there you can replace the current @Display(Model.ContentItems) with your own code - maybe something to iterate the list of posts and display the title and show a link to the post (or a summary of the content). If you are unsure about doing this, post another question here where it will be easier for me (or someone else) to answer :-)Kauri
B
2

Other than coding your own view, there are two other ways to customize what is shown.

  1. Placement.info file. you can tell it what fields to show for a given contentType and/or DisplayType (summary or detail.) You can also tell it what order to display the fields.

From the sample file in the thememachine theme.

<Match ContentType="Blog">
  <Match DisplayType="Summary">
    <Place Parts_Blogs_Blog_Description="Content:before"
         Parts_Blogs_Blog_BlogPostCount="Meta:3"/>
  </Match>
</Match>
  1. A quick hack is to use CSS to hide the content you don't want. I used this for blogPost metadata before I discovered the placement.info

BTW - I don't know if your familiar with the designer tools module, but it's invaluable!

Bogbean answered 18/7, 2011 at 21:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.