Copied to clipboard

Flag this post as spam?

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


  • Craig100 1110 posts 2440 karma points c-trib
    Aug 08, 2017 @ 14:55
    Craig100
    0

    Umb 7.6.4

    Hi,

    Using the tag datatype for the first time. Have a list of news items, some tagged, some not and a list of tags. When I click on a tag I want to reload the page and only show news items of the relevant tag. I have :

    var cat = Request.QueryString["cat"];
    var articleList = Model.Descendants().Where(x => x.IsVisible() && x.GetPropertyValue<bool>("hideFromNav") == false).OrderByDescending(x => x.CreateDate);
    

    I'm hoping I can add another WHERE clause to filter on the value of "cat" but completely stumped as to how to go about it. Not sure what I should be querying on to be honest. Docs and Google hasn't helped much. Even a Foreach look would be ok, but again, I don't know what criteria to search on.

    Any advice appreciated.

  • Craig100 1110 posts 2440 karma points c-trib
    Aug 08, 2017 @ 18:50
    Craig100
    100

    Well I got it done but I'm not happy as it looks like I'm running two queries all the time and only using one. If anyone can suggest a better way I'd love to hear it. The main issue is that the articles may not have tags so I want to show them all initially.

    var cat = Request.QueryString["cat"];
    
    var TaggedArticleList = Umbraco.TagQuery.GetContentByTag(cat, "Articles");
    
    var RawArticleList = Model.Descendants().Where(x => x.IsVisible() && x.GetPropertyValue<bool>("hideFromNav") == false).OrderByDescending(x => x.CreateDate);
    
    List<IPublishedContent> combinedResults = new List<IPublishedContent>();
    if(cat != null) {
        combinedResults.AddRange(TaggedArticleList);
    } else {
        combinedResults.AddRange(RawArticleList);
    }
    

    Thanks to Craig Mayers for the combinedResults code here: https://our.umbraco.org/forum/extending-umbraco-and-using-the-api/85839-using-two-tag-groups-for-one-search

Please Sign in or register to post replies

Write your reply to:

Draft