Copied to clipboard

Flag this post as spam?

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


  • Robin Hansen 135 posts 368 karma points
    Jun 12, 2014 @ 14:32
    Robin Hansen
    0

    Get a distinct list of Parent.Id's

    I've a site with a blog page - All blogItems are sorted under each Blogger - However the blogger is not displayed on the webpage, but info about the blogger is displayed on each blogItm instead... - here's how my nodetree looks like:

    Root

    + Blogs (nodeId: 1234)

    + + Blogger (<-- this is not displayed on the web)

    + + + BlogItem (<-- theese are linked to directly from Blogs)

    + + + BlogItem

    + + + BlogItem

    What I would like to do is display a table of the 9 latest active Blogger - here's how my code looks like:

    @{
        var startNode = 1234;
        var items = startNode.Descendants();
    }
    <table class="table bloggers">
        @foreach (var page in items.OrderBy("CreateDate desc").Take(9).InGroupsOf(3))
        {
            <tr>
            @foreach (var row in page)
            {
                <td><a href="@row.Url" title="@row.Parent.blogAuthor"><img src="@Umbraco.Content(row.Parent.id).GetCropUrl("blogImage", "blogger_thumb")" class="img-responsive" alt="@row.Parent.blogAuthor" /></a></td>
            }
            </tr>
        }
        </table>

    So far several bloggers are displayed multiple times - how can I make the list of Bloggers distincive...?

  • Mike Chambers 636 posts 1253 karma points c-trib
    Jun 12, 2014 @ 15:13
    Mike Chambers
    0
    myList.GroupBy(test => test.id).Select(group=>group.First());

    http://stackoverflow.com/questions/19406242/select-distinct-using-linq

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Jun 12, 2014 @ 15:20
    Dave Woestenborghs
    1

    I think you should have something like this :

    startNode.Descendants.OrderByDescending(x => x.CreateDate).Distinct(x => x.Parent).Take(9)

    This is untested.

  • Robin Hansen 135 posts 368 karma points
    Jun 14, 2014 @ 11:56
    Robin Hansen
    100

    This one nailed it - Dawoe U Rock >:-)

    IEnumerable<umbraco.NodeFactory.Node> items = uQuery.GetNodesByType("blogIndlaeg").OrderByDescending(r => r.CreateDate).DistinctBy(x => x.Parent.Id).Take(9);
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies