Copied to clipboard

Flag this post as spam?

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


  • Milly 30 posts 130 karma points
    Oct 19, 2015 @ 09:31
    Milly
    0

    Gather newest items and display on separate page

    Hi all, I am new to Umbraco and also Razor, so please excuse my lack of knowledge, I have a lot to learn.

    So far, I have managed to put together a site where a user can easily upload a product into a number of pre-defined categories (shown below, seating, lighting etc). The items are displayed in a gallery style grid, where each item is also clickable and has its own child page with extra info. Each category is a page in itself, e.g this is the "tables and desks" test page:

    enter image description here

    This part is all working fine, hoorah! But now I'm stuck..

    Now I would like to add two extra pages, a "new stock" page, and a "sold" page. I would like the "new stock" page to display six of the most recently uploaded items in the same gallery format as the above page. It needs to gather items from all categories, is this possible? If so, how would I go about doing this? My content structure is here:

    enter image description here

    Secondly, I'd like each item to have a "sold" checkbox in the CMS for the user to tick when he has sold an item. The item will then be transferred to the "sold" page, and again displayed in the gallery format.

    Thank you in advance for any advice on this! Am happy to post any code on request :).

  • gary 385 posts 916 karma points
    Oct 19, 2015 @ 13:03
    gary
    0

    Hi

    Will try to be simple and point you in the right direction - you may have to play with it a bit . . .

    New Stock

    @foreach ( var w in Model.Content.Descendants("stock").OrderBy("updateDate").Take(6)
    { " Your code for gallery" }
    

    For Sold - add a property of Sold to your doctype of type "True/False". Then use the above code but add a Where statement.

    ie - .Where("sold" == "true") the exact order you can determine. Probably OrderBy then Where then Take.

    As said, this is not a perfect answer, but all is possible just need to get the properties correct.

    Hope it helps

    G

  • Milly 30 posts 130 karma points
    Oct 29, 2015 @ 16:45
    Milly
    0

    Hello,

    Apologies for the delayed response, and thank you for your answer!!

    I have only just managed to get this working (I haven't had much free time), it's nearly doing what I want, it's showing the 6 newest item categories in my gallery format. enter image description here

    However I require it to go one page deeper and get the latest actual item from each category.. If it is easier I can have it gather the latest 2 items per category, rather than the latest 6 items uploaded to the whole site, if that makes sense!!

    I'm guessing I need some sort of child of children statement?!

    Thanks in advance for any help :)

  • gary 385 posts 916 karma points
    Oct 29, 2015 @ 17:34
    gary
    0

    Hi Milly

    Can you post some code?

    Will be easier to help.

    Regards

    Gary

  • Milly 30 posts 130 karma points
    Oct 29, 2015 @ 21:51
    Milly
    100

    Hello,

    I have managed to figure out a solution which works, however I have resorted to using Umbraco.Content("id").. is there any downside to using this?

    This is my working code:

                @foreach ( var item in Umbraco.Content(1137).Descendants().OrderBy("updateDate desc").Take(6))
                    { * gallery code.. * }
    

    Now for the "sold" page..

    Thanks!

  • Milly 30 posts 130 karma points
    Oct 29, 2015 @ 22:30
    Milly
    0

    Hi again,

    Just a heads up that I've managed to get all of the pages working as I'd liked, so thank you very much for your help, much appreciated!

    M

  • Nathan Woulfe 447 posts 1665 karma points MVP 5x hq c-trib
    Oct 29, 2015 @ 22:39
    Nathan Woulfe
    0

    Worth considering too as your stock inventory grows - it will be faster to grab the appropriate items from the Examine index rather than traversing the content tree.

Please Sign in or register to post replies

Write your reply to:

Draft