【发布时间】:2014-02-28 10:12:20
【问题描述】:
我有一个脚本,列出了我所有的新闻站点。 现在我的输出是:
<section class="news-list">
<article class="news-item top-news">
<a href="/nyheder/dbu-nyhed-4/">DBU Nyhed 4 (Topnyhed)</a>
</article>
<article class="news-item top-news">
<a href="/nyheder/dbu-nyhed/">DBU Nyhed (Topnyhed)</a>
</article>
<article class="news-item">
<a href="/nyheder/dbu-nyhed-3/">DBU Nyhed 3</a>
</article>
<article class="news-item">
<a href="/nyheder/dbu-nyhed-2/">DBU Nyhed 2</a>
</article>
</section>
我想做的是:
- 围绕所有“头条新闻”文章项创建一个包装 div
代码如下:
@if (CurrentPage.Children.Where("Visible").Any())
{
<section class="news-list">
@* For each child page under the root node, where the property umbracoNaviHide is not True *@
@foreach (var childPage in CurrentPage.Children.Where("Visible").OrderBy("topNews desc, CreateDate desc"))
{
var isTopNews = childPage.topNews;
if (isTopNews)
{
<article class="news-item top-news">
<a href="@childPage.Url">@childPage.Name (Topnyhed)</a>
</article>
}
else
{
<article class="news-item">
<a href="@childPage.Url">@childPage.Name</a>
</article>
}
}
</section>
}
【问题讨论】:
-
然后创建,有什么问题?
-
为什么不创建 2 个列表,一个包含 topnews 项目,一个不包含,这样您就可以创建 2 个 foreach 循环?