Copied to clipboard

Flag this post as spam?

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


  • Owain Williams 481 posts 1413 karma points MVP 7x c-trib
    Jul 03, 2015 @ 11:11
    Owain Williams
    0

    Best way to organise news articles?

    Hi, How do people organise their news / pages that required to be archived over a period of time? I was looking at the package DateFolder but it seems to be pretty out of date now and unsupported for U7.

    I'm looking to have articles organised by year, month, day so that the URL would look something like http://mysite/news/2015/01/23/aNewsArticle this would then allow me to potentially have another 'aNewsArticle' within a different year, month or date.

    Any ideas on the best way to do this would be great, other than me creating a root page for each year, month and day!

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 03, 2015 @ 12:07
    Dennis Aaen
    100

    Hi Owain,

    Perhaps you should have a look at the packages called udatefoldersy

    https://our.umbraco.org/projects/backoffice-extensions/udatefoldersy

    This package should support Umbraco 7 and do what you are trying to archive.

    Hope this helps and can be a solution for you.

    /Dennis

  • Owain Williams 481 posts 1413 karma points MVP 7x c-trib
    Jul 03, 2015 @ 13:43
    Owain Williams
    0

    Thanks Dennis, Just trying to configure that package just now - thanks I'll see if this does what I need. Fingers crossed :)

  • Owain Williams 481 posts 1413 karma points MVP 7x c-trib
    Jul 10, 2015 @ 13:54
    Owain Williams
    0

    As a follow on from this, I was wondering how I would be able to display the contents of the date folders.

    I have a structure now in the backend like

    Root Folder
    --Year 
         --Month
            --Date
               --pageTitle
    

    I would then like to show a similar structure on the front end. i.e. Latest articles

    2015
     July
     10/07/2015 - My article
     05/07/2015 - Another article
    

    And the title would be a link to that article. I thought I could just use the wizard but it doesn't seem to pull the information for me. I'm using the udatefoldersy as suggested.

    Thanks,

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 13, 2015 @ 21:16
    Dennis Aaen
    0

    Hi Owain,

    Sorry for the little late answer. Now I had the time to create a good starting point for you. This code below should create what you are after.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    
    @{ 
        var selection = CurrentPage.uDateFoldersyFolderYear.Where("Visible"); 
    }
    
    @if (selection.Any())
    {
        <ul>
            @foreach (var item in selection)
            {
    
                var newsItems = item.Descendants("umbNewsItem").Where("Visible");
                var month = item.Descendants("uDateFoldersyFolderMonth").Where("Visible");
                <li>
                    <a href="@item.Url">@item.Name</a> (@newsItems.Count())
                    <ul>
                    @foreach(var newsitem in month){ 
    
    
    
                        <li>
                             <a href="@newsitem.Url">@newsitem.CreateDate - @newsitem.Name</a> 
                        </li>
                    }
                    </ul>   
                </li>
    
            }
        </ul>
    }
    

    Just remember to change the document type aliases so they are matching your case. In my example I have used a Partial view macro file, but you cn use the same code in a Partial view.

    The only difference is the inherits linie, it should be changed from

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    

    To

    @inherits UmbracoTemplatePage
    

    Hope this helps,

    /Dennis

  • Owain Williams 481 posts 1413 karma points MVP 7x c-trib
    Jul 14, 2015 @ 08:19
    Owain Williams
    0

    Hi Dennis, No need to apologise.

    I think my lack of understanding of Umbraco and possibly Razor is the major issue in me needing to post so much on here. I have copied your code, changes it slightly to put an else in after the if statement and it seems that, the if is never being executed for me.

    So the variable selection must be empty.

    Site backend structure

    That is my structure just now of my site. So you can see what I am trying to do. Now I want to display the 'Races' structure on a couple of different pages throughout the site but that should be possible with a partial view which I'll just call when I need it.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 14, 2015 @ 19:56
    Dennis Aaen
    0

    Hi Owain,

    I have had a other look at the code and make some adjustments to it. So hopefully it will work for you too.

    My content structure is like this, similar to yours. And I place the Razor macro on the template for the Races template.

    The code looks like this.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @{ 
        var selection = CurrentPage.uDateFoldersyFolderYear.Where("Visible"); 
    }
    
    @if (selection.Any())
    { 
         <ul>
            @foreach (var item in selection)
            {
    
                var newsItems = item.Descendants("umbNewsItem").Where("Visible");
                var month = item.Descendants("uDateFoldersyFolderMonth").Where("Visible");
                var days = item.Descendants("uDateFoldersyFolderDay").Where("Visible");
    
                <li>
                    @item.Name
                    <ul>
                    @foreach(var monthItem in month){ 
    
    
    
                        <li>
                             @monthItem.Name
    
                            <ul>
                            @foreach(var dayItem in days){ 
    
                                <li>
                                    @dayItem.Name
    
                                    <ul>
                                        @foreach(var newsItem in newsItems){ 
                                            <li>
                                                @newsItem.Name
                                            </li>
                                        }
                                    </ul>
    
                                </li>
                            }
                            </ul>
                        </li>
                    }
                    </ul>   
                </li>
    
            }
        </ul>
    }
    

    Just remember to change the document type aliases so they are matching your case. In my example I have used a Partial view macro file, but you can use the same code in a Partial view.

    I think the only document type alias you need to change is "umbNewsItem" to your alias of the document type that has a drinks.

    The only difference is the inherits linie, it should be changed from

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    

    To

    @inherits UmbracoTemplatePage
    

    Hope this helps,

    /Dennis

  • Owain Williams 481 posts 1413 karma points MVP 7x c-trib
    Jul 15, 2015 @ 12:22
    Owain Williams
    0

    I think I have found the problem, but unsure how to solve it.

    You mentioned that you put the code you supplied on the 'Races' template, that would explain the 'CurrentPage.' but I would like to display the information on 'Homepage' as well. I think that is why I am getting no results because it's looking for uDateFoldersyFolderYear on the homepage, not Races.

    How do I point my homepage, or any other page for that matter, to the Races node and then run the query?

    EDIT: I have it working on my races page, in a way, but as you will see from my screenshot, it's displaying the races wrongly. screenshot1

    if I compare that to the backend

    backend screenshot

    So close! :)

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 15, 2015 @ 18:00
    Dennis Aaen
    0

    Hi Owain,

    I have corrected the code now, and I have changed it so you can use it on the homepage template too.

    The only thing you need to change in the code below is the alias from "umbNewsOverview" to the alias that your Races document type has.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    
    
    @{ 
    
        var selection = CurrentPage.AncestorOrSelf(1).Descendants("umbNewsOverview").FirstOrDefault(); 
    
    
    
        var yearFolders = selection.Children.Where("Visible");
    
    }
    
    
    
    <ul>
    
        @foreach (var yearFolder in yearFolders){ 
    
            <li>
    
                @yearFolder.Name
    
    
    
                <ul>
    
                @foreach(var monthFolder in yearFolder.Children.Where("Visible")){ 
    
                    <li>
    
                        @monthFolder.Name
    
                            <ul>
    
                                @foreach(var dayFolder in monthFolder.Children.Where("Visible")){ 
    
                                    <li>
    
                                        @dayFolder.Name
    
    
    
    
    
                                        <ul>
    
                                            @foreach(var newsitem in dayFolder.Children.Where("Visible")){ 
    
                                                <li>
    
                                                    @newsitem.Name
    
                                                </li>
    
                                            }
    
                                        </ul>
    
                                    </li>
    
                                }
    
                            </ul>
    
                    </li>
    
                }
    
                </ul>
    
            </li>
    
        }
    
    </ul>
    

    Hope this helps,

    /Dennis

  • Owain Williams 481 posts 1413 karma points MVP 7x c-trib
    Jul 16, 2015 @ 07:34
    Owain Williams
    0

    Brilliant, absolutely brilliant. Thank you for all your help Dennis. I'm going to read your code and learn from it.

    Thanks again, this has been a massive help.

    O.

Please Sign in or register to post replies

Write your reply to:

Draft