如果您需要创建标签作为带有选项的链接以显示被标记的产品,那么您可以创建名为 ../search.aspx?tag=tagname 的新页面,然后搜索该标签中的产品,代码如下:
@inherits umbraco.MacroEngines.DynamicNodeContext
@using System.Text
@using umbraco.MacroEngines
@using umbraco.cms.businesslogic.Tags
@{
string searchFor = Request["tags"];
if(string.IsNullOrEmpty(searchFor))
{
@* No tags were specified *@
<p>Please specify a tag to search for</p>
return;
}
// this is to search from the tags added and then get all the nodes
var matchingNodes = Tag.GetNodesWithTags(searchFor).ToList();
string tagsText = searchFor.Split(',').Count() > 1 ? "tags" : "tag";
if (matchingNodes.Count < 1)
{
@* No results were found for the specified tags *@
<p>No tagged items were found that matched the @tagsText: @searchFor</p>
return;
}
@* Some results were found for the specified tags *@
<p><strong>@matchingNodes.Count</strong> products were found that matched the @tagsText: "@searchFor"</p>
<ul>
// go through the code and create URL for that product
@foreach (var node in matchingNodes)
{
dynamic dn = new DynamicNode(node.Id);
<li><a href="@dn.Url">@dn.Name</a></li>
}
</ul>
}
你可以参考这篇文章,因为我已经检查过了,点击这里,中途你会看到这段代码
让我知道任何更多的解释需要。我已经对此发表了评论,以便您可以了解代码。