Copied to clipboard

Flag this post as spam?

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


  • Mark Evans 86 posts 116 karma points
    Aug 28, 2014 @ 09:23
    Mark Evans
    0

    content filtering

    i have a scenario where different levels of my site each have their own news items.

    i want to set it up so that top level (home) will show all news items (for home and all levels below) whereas a page at  level 2 for example will show only news for that page and child pages.... level 3 only news for that level page and any children etc... (ie news item filter down but not up)

    do i need lots of if else statements checking on the actual page name to do this?

    i tried using the document type alias (as level 2 is one particular type) but this pulls in the news for all "divisions" at that level whereas id want the news for the particular division the user has selected....

    is it just a case of getting the current page and children?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Aug 28, 2014 @ 11:54
    Dennis Aaen
    0

    Hi Mark,

    I assume that you are using Razor, For my example to help you I have used the Txt starter kit.

    The way that you can list all your news items, on the frontpage no matter what level that you are on you could use the Descendants() axis, and limted to take your news items, like this,

    @inherits Umbraco.Web.Macros.PartialViewMacroPage

    @{
        var root = CurrentPage.AncestorOrSelf(1);
        var newsItems = root.Descendants("umbNewsItem");
            <ul>
                @foreach(var item in newsItems){
                    <li>
                        <a href="@item.Url">@item.Name</a>
                    </li>
                }
            </ul>
    }

    As you can see I use Partial View Macros, to get it work in your case, remeber to change the umbNewsItem, so it match the alias of your news items.

    For the divistions news items, you can use the children of the currentpage, and you said, but, if you can create other type of pages, they will come in the navigation too. You could use this snippet of code, it only takes the news items.

    And as I started to say I have taken point in the Txt starter kit, so my news items, is live under a news overview page, and I place the macro on the template for the news overview page, and it will print a link to alle the news items, that you have underneath the overview page.

    This is the pre-define code snippet called List Child Pages With Doctype

    @inherits Umbraco.Web.Macros.PartialViewMacroPage

    @{   
        @*Build a query and return the visible items *@
        var selection = CurrentPage.umbNewsItems.Where("Visible");
    }

    @*Determine if there are any nodes in the selection, then render list *@
    @if(selection.Any()){

       <ul>
         @foreach(var page in selection){               
           <li><a href="@page.Url">@page.Name</a></li>
         }                
       </ul>            

    }

    Hope this hleps, or donĀ“t hestitate to write again.

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft