Copied to clipboard

Flag this post as spam?

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


  • Sharmarke Hujale 103 posts 346 karma points
    Feb 06, 2016 @ 19:35
    Sharmarke Hujale
    0

    Making a navigation with categories

    Hi guys

    I'm making a news site. This news site has categories - so my content tree looks like this:

    enter image description here

    How do I make a navigation out of this? So it looks like this:

    News in somali - News in english - About us - Contact

    I would appreciate some help

    //Sharmarke

  • Sharmarke Hujale 103 posts 346 karma points
    Feb 06, 2016 @ 21:14
    Sharmarke Hujale
    0

    Anyone?

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Feb 06, 2016 @ 23:14
    Nicholas Westby
    0

    Not sure what particular part you are having an issue accomplishing. Here are the high-level steps:

    • Fetch the ID's of the pages you want in your navigation (there are many ways to do this, but I prefer Archetype for this purpose).
    • Convert the ID's to URL's and labels.
    • Render the menu markup using the URL's and labels.

    If your provide further details, we may be able to provide further insight.

  • Sharmarke Hujale 103 posts 346 karma points
    Feb 06, 2016 @ 23:51
    Sharmarke Hujale
    0

    When I go to the developer section and create a partial macro file - I first at hand used the navigation snippet to do a dynamic navigation

    So that my navigation would look like this:

    News in somali - News in English - About us - Contact

    But then I created a new DocType "Category" and I allowed "News in somali and News in Somali" to be its children, so in the URL I would get:

    www.mypage.com/category/news-in-somali

    But then I was stucked, because the navigation snippet that I was using is only taking the root of the content tree's children pages (about us, contact us)

    And it doesn't take the children pages' pages (news in somali and news in english)

    I could just hard code it, but I want to make dynamic instead - and I used the umbracoNaviHide to hide category from the navigation

    Hope this was understandable

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Feb 07, 2016 @ 18:32
    Nicholas Westby
    0

    Is there any reason you need to do it the way you are trying to do it?

    I would really recommend Archetype for something like this: https://our.umbraco.org/projects/backoffice-extensions/archetype/

    Alternatively, if your menu is only one level (i.e., no menu items under the top-level menu items), you can simply use a multinode treepicker to choose which nodes you want to include in the menu.

    By the way, if you really must continue using whatever code snippet you are using, reply here with that code snippet and I'll take a look.

  • Sharmarke Hujale 103 posts 346 karma points
    Feb 07, 2016 @ 19:16
    Sharmarke Hujale
    0

    Sorry for not showing the snippet in my last reply - but I wasn't on my pc at that time. But here is the snippet:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @{ var selection = CurrentPage.Site().Children.Where("Visible"); }
    

    It gives me "About us", "Contact" and "Category" - but I don't want the category to be there, so I used the umbracoNaviHide - but I want its two children to be apart of the navigation.

    How do I achieve that?

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Feb 07, 2016 @ 20:04
    Nicholas Westby
    0

    I would recommend avoiding dynamic syntax (anytime you use "CurrentPage", you are using dynamic syntax). This should work given the structure you described:

    @{
        var home = Model.Content.AncestorOrSelf(1);
        var selection = home.Children
            .SelectMany(x => x.IsVisible()
                ? new[] { x }
                : x.Children.Where(y => y.IsVisible()));
    }
    <ul>
        @foreach (var item in selection)
        {
            <li class="@(item.IsAncestorOrSelf(Model.Content) ? "current" : null)">
                <a href="@item.Url">@item.Name</a>
            </li>
        }
    </ul>
    

    However, I would still recommend a multinode treepicker or Archetype. They are more flexible solutions.

  • Sharmarke Hujale 103 posts 346 karma points
    Feb 07, 2016 @ 20:29
    Sharmarke Hujale
    0

    Could you give me a link to an article, documentation or a forum post about the multinode treepicker, because I've never used it before?

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Feb 07, 2016 @ 20:38
    Nicholas Westby
    0

    It is built in to Umbraco 7 and is one of the most useful property editors: https://our.umbraco.org/documentation/getting-started/backoffice/property-editors/built-in-property-editors/multinode-treepicker

    In your case, you'd add a MNTP property (likely to your home node) and use it to pick the content nodes you want to be in your navigation menu.

  • Sharmarke Hujale 103 posts 346 karma points
    Feb 07, 2016 @ 22:20
    Sharmarke Hujale
    0

    Very nice!

    Thank you for your help and time.

Please Sign in or register to post replies

Write your reply to:

Draft