链接Orchard CMS中的博客文章?

时间:2016-09-06 05:02:10

标签: orchardcms

我在 Orchard CMS 中有一个博客帖子列表。这是我的代码:

@{
    IEnumerable<object>
    blogPosts = Model.ContentItems;
    Model.ContentItems.Classes.Add("content-items");
    Model.ContentItems.Classes.Add("blog-posts");
}

<div class="row">
    @foreach (var item in blogPosts)
    {
        <div class="col-md-4 col-sm-6">
            <div>
                <div class="blog-seg post-item seg">
                    <div>@Display(item)</div>
                </div>
            </div>
        </div>
    }
</div>

我希望每个DIV都有一个帖子链接。我怎么能这样做?

2 个答案:

答案 0 :(得分:2)

使用以下内容显示内容项的链接:

@using Orchard.ContentManagement;

@{
    IEnumerable<dynamic>
        blogPosts = Model.ContentItems.ContentItems;
    Model.ContentItems.Classes.Add("content-items");
    Model.ContentItems.Classes.Add("blog-posts");
}

<div class="row">
    @foreach (var item in blogPosts) {
        <div class="col-md-4 col-sm-6">
            <div>
                <div class="blog-seg post-item seg">
                    <div>
                        @Html.ItemDisplayLink(item.ContentItem as IContent)
                    </div>
                </div>
            </div>
        </div>
    }
</div>

答案 1 :(得分:0)

@using Orchard.ContentManagement;
@{
IEnumerable<dynamic>
    blogPosts = Model.ContentItems;
Model.ContentItems.Classes.Add("content-items");
Model.ContentItems.Classes.Add("blog-posts");

}

<div class="row">
@foreach (var item in blogPosts)
{
    IContent contentItem = item.ContentItem;
    var metadata = contentItem.ContentItem.ContentManager.GetItemMetadata(contentItem);
    string alias = metadata.Identity.Get("alias");

    <div class="col-md-4 col-sm-6">
        <div>
            <div class="blog-seg post-item seg">
                <a href="~/@alias" style="display:block;">@Display(item)</a>
            </div>
        </div>
    </div>
}