我有一个脚本列出了我的所有newsitems。 现在我的输出是:
<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>
我想做的是:
代码如下所示:
@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>
}
答案 0 :(得分:1)
您应该将列表分成两部分:
@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").Where("topNews").OrderBy("CreateDate desc"))
{
<article class="news-item top-news">
<a href="@childPage.Url">@childPage.Name (Topnyhed)</a>
</article>
}
@foreach (var childPage in CurrentPage.Children.Where("Visible").Where("not topNews").OrderBy("CreateDate desc"))
{
<article class="news-item">
<a href="@childPage.Url">@childPage.Name (Topnyhed)</a>
</article>
}
</section>
}
然后将div包裹在你需要的地方。