【问题标题】:tagging in umbraco 4.11 just like stackoverflow在 umbraco 4.11 中标记就像 stackoverflow
【发布时间】:2013-03-16 19:44:50
【问题描述】:

我使用了snipper标签系统和下面的文章:

http://daniel.streefkerkonline.com/tag/umbraco/

我可以成功安装和使用sniper标签系统。但是当我浏览页面时..标签显示为文本而不是超链接...

我是不是错过了什么。是一些 javascript 文件还是我缺少包含标签的一些步骤?

有什么想法吗? 这是我的页面: http://www.leezardpharma.com/pharmacy/our-products/weight-loss-medicine/gastro1.aspx

这里有相关标签,因为 snipper ..但它们不可点击。

【问题讨论】:

    标签: content-management-system umbraco umbraco-tags


    【解决方案1】:

    如果您需要创建标签作为链接选项以显示被标记的产品,那么您可以创建名为 ../search.aspx?tag=tagname 的新页面 然后搜索该TAG中的产品,代码如下:

    @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>
    }
    

    你可以参考这篇文章,因为我已经检查了它click here 并且在中途你会看到这个代码

    如果需要更多解释,请告诉我。我已对此进行了评论,以便您了解代码。

    【讨论】:

    • 您好 Ankur,感谢您的回答。虽然不完全是我想要的,但它很有用。我希望标签 url 和 stackoverflow 一样。
    【解决方案2】:

    你确定要这样做吗?

    <ul>
      @foreach (var node in matchingNodes)
      {
        dynamic dn = new DynamicNode(node.Id);
    
        <li><a href="@dn.Url">@dn.Name</a></li>
      }
    </ul>
    

    有些地方看起来不对,您在此处显示标签:

    这两个链接来自哪里?

    不需要 javascript 或任何花哨的东西。这一切都是在服务器端的 razor 中完成的。

    【讨论】:

    • 嗨丹尼尔,你在我实现 Ankur 的代码后查看了链接。现在我可以拥有链接,但我想要的是 stackoverflow 类型标签 URL。
    【解决方案3】:

    我写了狙击手标记控件。

    如果您想要标签的友好 URL, 创建重写规则以将 /tags/([\w]*) 重写映射到 tagsearch.aspx?tag=$1 然后实现 tagsearch.aspx 以获取该标记参数并返回包含它的任何页面,如上所述。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多