Copied to clipboard

Flag this post as spam?

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


  • Meni 271 posts 507 karma points
    Apr 26, 2013 @ 03:13
    Meni
    0

    How to display multiple nodes?

    Hello, 

    I try to display content from multiple nodes in my magazine. I have several acrhieve pages for each category (sport / music / tech / etc) but I want in one page to show all the news - how do I do it?

    This is my code: 

    dynamic node = Library.NodeById(1095);  
    
    var pagesToList = @node.Children.Where("Visible");
    @foreach (var newsItem in pagesToList)
    {       
        var selectedMedia = @newsItem.Media("articleImg");
    
        <div class="news_box">                                
                    <div class="img_frame">
                        <a href="@newsItem.Url" class="img_link">                  
                            <img src="@selectedMedia.umbracoFile" width="140" height="100" alt="@selectedMedia.Name"/>
                        </a>
             </div>                    
             <div class="news_frame">
               <h2>
                    <a href="@newsItem.Url" class="news_link">
                           @newsItem.title 
                    </a>
               </h2>
               <p>                        
                      @newsItem.metaDescription                                  
                      <a href="@newsItem.Url" class="news_link">Read >></a>                        
                </p>                    
          </div>    
    
         <div style="clear:both"></div>                
          </div>
    
    
     }

    I tried to change from 

    dynamic node = Library.NodeById(1095);

    to

    dynamic node = Library.NodesById(1095, 1077);

    But it didn't work and I got error ... 

    How do I do it? Is there any way to do it

    Thanks. 

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Apr 26, 2013 @ 08:29
    Dave Woestenborghs
    0

    Hi Meni,

    Can you show me how your content is structured in the backend ?

    Dave

  • Meni 271 posts 507 karma points
    Apr 26, 2013 @ 11:28
    Meni
    0

    Yes,

    Home Page.

    Then under it I have the magazine folder which inside it (childs) the magazine (archieve) pages - sport / music / tech / lifestyle / etc. then (in parrallel to the magazine-archieve pages) I have folder for each category - sport / music / tech - which inside each catgegory I have another folder - 2013 then news folder - then the news pages with the properties - title / articleImg / metaDescription - which is also the article summary which show at the magazine pages and home pages

  • Rich Green 2246 posts 4008 karma points
    Apr 26, 2013 @ 11:32
    Rich Green
    0

    Hey Meni,

    It might be better to take a screenshot and post it here.

    Rich

  • Charles Afford 1163 posts 1709 karma points
    Apr 26, 2013 @ 13:51
    Charles Afford
    0

    I think what he wants to do is trying to do is start from Root(Home) and recusivly go into each of the sub nodes.  Select the news page and render it out?

    Home

    >Node

    > Archive

    > News (Render Me)

    >Node

    > Archive

    > News (Render Me)

    > Node

    > Archive

    > News (Render Me)

     

    I could be really along way off.  Screen shot would be really usefull.  Thanks.  Charlie :)

  • Rich Green 2246 posts 4008 karma points
    Apr 26, 2013 @ 14:27
    Rich Green
    0

    Have a look at the Site Map XSLT / Razor template that comes out the box with Umbraco, this can be modified to do this.

    Rich

  • Funka! 398 posts 661 karma points
    Apr 30, 2013 @ 19:27
    Funka!
    0

    For this type of scenario I love to use the XPath operator (yes, this works in Razor!) as follows:

    dynamic node = Library.NodeById(1095);   // starting/common ancestor node
    var pagesToList = @node.XPath(".//newsItem").Where("Visible"); //assume the pages you want displayed are actually called "newsItem"

    The XPath query will descend all the way down the tree, grabbing anything named "newsItem".

    You can also throw an OrderBy() on the returned collection, maybe even a Take(), for instance if you wanted to display the last 5 updated news items.

    Best of luck!

Please Sign in or register to post replies

Write your reply to:

Draft