Copied to clipboard

Flag this post as spam?

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


  • Steve 2 posts 93 karma points
    Mar 08, 2017 @ 20:50
    Steve
    0

    Find All Pages Containing Tags in Razor

    Hello,

    I have pages containing tags. Let's say Home has the tag home, Page 1 has the tag Sports and Page 2 has the tag Sports,Entertainment.

    How can I get a list of all pages that would contain the tag Sports and link to them?

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Mar 10, 2017 @ 13:45
    Alex Skrypnyk
    1

    Hi Steve

    I think you have to try GetContentByTag method:

    var taggedContent = Umbraco.TagQuery.GetContentByTag("tagname");
    

    Then you will be able to get all properties of tagged pages. Hope this is what you want to achieve.

    Thanks,

    Alex

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Mar 14, 2017 @ 14:22
    Alex Skrypnyk
    0

    Hi Steve

    Did you find out how to do it?

    /Alex

  • Steve 2 posts 93 karma points
    Mar 16, 2017 @ 15:43
    Steve
    100

    Hi Alex,

    Yes I figured out how to do it. I did it this way in the end:

    @{
    //Get All Available Tags for the Sports Page
    var allTags = Umbraco.TagQuery.GetAllTags();
    if(CurrentPage.Name == "Sports") 
    {
        <ul class="list-inline">
            <li><a href="@CurrentPage.Url">All Tags</a>
            @foreach (var tag in allTags)
            {
                var url = @CurrentPage.Url + "?tag=" + HttpUtility.UrlEncode(@tag.Text);
                <li><a href="@url">@tag.Text</a></li>
            }
    
        </ul>
    }
    

    }

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Mar 16, 2017 @ 15:44
    Alex Skrypnyk
    0

    Hi Steve

    Glad that you figured out how to do it. Thanks for sharing the code example!

    Have a nice day.

    /Alex

Please Sign in or register to post replies

Write your reply to:

Draft