[英]2sxc blog app posts and DNN search
在使用 2sxc 博客應用程序時,我注意到 DNN 搜索結果顯示了所有帖子,但帖子標題的鏈接是主博客頁面,而不是實際的帖子鏈接。
示例搜索結果顯示:
頁面標題:我是帖子標題
上面標題的鏈接是: /blog
什么時候應該是: /blog/post/i-am-a-post-title
通過將以下內容添加到 cshtml 代碼中,設法修改了搜索結果:
@using ToSic.Eav.DataSources
@using ToSic.SexyContent.Search
@using DotNetNuke.Entities.Modules
@functions{
// Prepare the data - get all categories through the pipeline
public override void CustomizeData()
{
}
/// <summary>
/// Populate the search - ensure that each entity has an own url/page
/// </summary>
/// <param name="searchInfos"></param>
/// <param name="moduleInfo"></param>
/// <param name="startDate"></param>
public override void CustomizeSearch(Dictionary<string, List<ISearchInfo>> searchInfos, ModuleInfo moduleInfo, DateTime startDate)
{
foreach (var si in searchInfos["Default"])
{
si.QueryString = "post=" + si.Entity.EntityId;
}
}
}
但我希望顯示UrlKey而不是si.Entity.EntityId ,有什么想法嗎?
簡單 - 只需轉換為 DynamicEntity - https://github.com/2sic/2sxc/wiki/DotNet-DynamicEntity :
foreach (var si in searchInfos["Default"])
{
si.QueryString = "post=" + AsDynamic(si.Entity).UrlKey;
}
來自瑞士的愛 :) PS:如果這解決了您的問題,請標記為已回答
foreach (var si in AsDynamic(searchInfos["Default"]))
{
si.QueryString = "post=" + si.UrlKey;
}
使 searchInfo 成為一個動態實體后,像“Title”這樣的屬性就起作用了。 但是屬性“UrlKey”不起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.