Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Thomas 315 posts 602 karma points c-trib
    Sep 21, 2017 @ 14:36
    Thomas
    0

    Get all pages with a tag ex. "apple" or "Samsung"

    Hey.

    I'm trying to get all pages that are tagged with a specific tag, ex. "apple", "samsung"

    I'm using this to list all the tags:

    @{
        var tagList = Umbraco.TagQuery.GetAllTags("news").OrderBy(t => t.Text);
        <ul>
            @foreach(var tag in tagList)
            {
                <li>@tag.Text</li>
            }
        </ul>
    }
    

    but I would like to get all pages with there url and name listet.

    Hope anyone can help, thanks

    // Thomas

  • Alex Skrypnyk 6131 posts 23950 karma points MVP 7x admin c-trib
    Sep 21, 2017 @ 14:48
    Alex Skrypnyk
    101

    Hi Thomas

    You can get all pages with this code:

    var nodesTags = Umbraco.TagQuery.GetContentByTag("testTag", "tagGroup");
    

    Example:

    @{
        var nodesTags = Umbraco.TagQuery.GetContentByTag("testTag", "news");
        <ul>
            @foreach (var node in nodesTags)
            {
                <li><a href="@node.Url">@node.Name</a></li>
            }
        </ul>
    }
    
  • Thomas 315 posts 602 karma points c-trib
    Sep 21, 2017 @ 14:55
    Thomas
    1

    Brilliant! Thanks Alex. Saved my day ! :D

  • Alex Skrypnyk 6131 posts 23950 karma points MVP 7x admin c-trib
    Sep 21, 2017 @ 14:58
    Alex Skrypnyk
    1

    You are welcome, Thomas, have a great rest of the day!

  • Thomas 315 posts 602 karma points c-trib
    Sep 21, 2017 @ 15:09
    Thomas
    0

    Thanks you, you too :)

Please Sign in or register to post replies

Write your reply to:

Draft