Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>
}
like image 897
joelnet Avatar asked Jul 18 '11 01:07

joelnet


2 Answers

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.

like image 134
mdm Avatar answered Oct 20 '22 10:10

mdm


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!

like image 20
DanielEli Avatar answered Oct 20 '22 11:10

DanielEli