SiteAzure获取上一个月范围内的文章信息
根据客户的要求,需要获取某个节点下,上一个月的前两条信息;默认标签有个近1月范围内的信息,但是不能明确如2021-12-01至2021-12-31之间的信息筛查!因此利用GetList()方法单独制作了;根据API接口文档的方法说明,如下图:
制作的标签如下:
@{
string Sort = Param.Sort ?? "Priority DESC,PublishTime DESC"; //排序
string nodeIdentifier = Param.NodeIdentifier;
string beginTime = Param.BeginTime;
var beginDate = DateTime.MinValue;
beginDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
if (!string.IsNullOrEmpty(beginTime) && DateTime.TryParse(beginTime, out beginDate))
{
beginDate = new DateTime(int.Parse(DateTime.Parse(beginTime).ToString("yyyy")), int.Parse(DateTime.Parse(beginTime).ToString("MM")), 1);
}
var endDate = beginDate.AddMonths(1);
int Count = Param.Count ?? 5;
int TitleLength = Param.TitleLength ?? 50; // 标题长度
int ImageWidth = Param.ImageWidth ?? 400; // 图片宽度
int ImageHeight = Param.ImageHeight ?? 300; // 图片高度
var LinkBlankTarget = Param.LinkBlankTarget ?? true; //否新窗口打开,true情况下由节点设置决定
bool IncludeChildNodes = Param.IncludeChildNodes ?? true;
bool initExtendContent = Param.initExtendContent ?? false;
var articles = new ArticleService().GetList(nodeIdentifier, Count, IncludeChildNodes, initExtendContent, Sort, x => x.PublishTime >= beginDate && x.PublishTime < endDate);
ResizeModelType resizeType = Param.ResizeModelType ?? ResizeModelType.CenterCrop;
Node node = null;
string target = "";
}
@if ((articles != null) && articles.Any())
{
foreach (var article in articles)
{
node = new NodeService().GetEntity(x => x.NodeId == article.NodeId);
target = LinkBlankTarget && node != null && node.ContentOpenInNewTarget ? "_blank" : null;
<li>
<div class="pic">
<a href="@article.ContentUrl()" target="@target">
@if (string.IsNullOrEmpty(article.FeaturedImage))
{
<img alt="@article.Title" src="~/content/_common/base/img/nopic.gif" width="@ImageWidth" height="@ImageHeight" />
}
else
{
<img alt="@article.Title" src="@Power.Thumbnail(article.FeaturedImage.ToUrl(), ImageWidth, ImageHeight)" width="@ImageWidth" height="@ImageHeight" />
}
</a>
</div>
<a class="tit" href="@article.ContentUrl()" title="@article.Title" target="@target">@article.Title.CutText(TitleLength, "…")</a>
</li>
}
}
else{
<li class="noData">暂无资料</li>
}
此标签默认为筛选当前月份的信息;
如果要使用上一个月则beginTime 参数传入上一个月日期;
使用如下:
<!-- 考评排行榜 S -->
<dl class="box-rank">
@{
//当前日期
int year = DateTime.Now.Year;//当前年
int mouth = DateTime.Now.Month;//当前月
var curDate = year + "-" + mouth.ToString("00") +"-01";//当月日期
int beforeYear = (mouth <= 1)?year - 1:year;
int beforeMouth = (mouth <= 1)?12:mouth - 1;
var beforeDate = beforeYear + "-" + beforeMouth.ToString("00") + "-01";//上月日期
//栏目信息循环
var rankNodeService = new NodeService();
var rankNode = rankNodeService.GetNodeByIdentifier("kpphb");
var rankChildNodes = rankNodeService.GetChildNodeList(rankNode).Take(5);
}
<dt class="mHd">
<h3><span class="year">@beforeYear</span>@Power.Node("kpphb").NodeName</h3>
<div class="info">
@Power.Url.NodeLink("bdgz", new { @class = "tip-more" })
<a href="javascript:;" class="more">历史查询</a>
<span class="month">@beforeMouth.ToString("00")月</span>
</div>
</dt>
<dd class="mBd">
<div class="hd">
<ul class="tabList">
@foreach (Node childNode in rankChildNodes)
{
<li>@Power.Url.NodeLink(childNode.Identifier)</li>
}
</ul>
</div>
<div class="bd">
@foreach (Node childNode in rankChildNodes)
{
<ul class="datepicList">
@Power.Partial("文章信息列表-时间筛查式", new { Count = 2, NodeIdentifier = childNode.Identifier, beginTime=beforeDate, TitleLength = 36, ImageWidth = 471, ImageHeight = 432, Sort="Priority DESC,PublishTime DESC" })
</ul>
}
</div>
</dd>
</dl>
<!-- 考评排行榜 E -->
页面效果:
用户登录
还没有账号?
立即注册