How to create a news archive in umbraco?

I am trying to create a news archive in umbraco where a list of news pages organized by month will be displayed. Each page will display a list of news for this month.

I followed the tutorial for creating news , but I'm not sure how to create an archive. There seems to be no link to this online. Of course, this is a common example of using CMS.

Does anyone have any ideas (preferably in razorscript if coding is required)?

+4
source share
2 answers

As a result, I used the datefolders package, which automatically sorts the news in the correct folder of the year and month based on a predefined date field, as @amelvin's answer . The advantage of the finalists is that it makes it easy for the user to manually sort their articles in the correct folder and maintain this organization. They can simply right-click a news container item, create an article, set a date, and it will only appear in the right folder. In addition, it changes the folder when the date changes.

In terms of displaying archives, I had the following razor code, where NewsListing is the document type for news items, and NewsItem is the document type for the news item:

Archive list in the sidebar

 <umbraco:Macro runat="server" language="cshtml"> @{ dynamic newsListingNode = Model.AncestorOrSelf(1).DescendantsOrSelf("NewsListing").First(); } <div class="archive"> <ul> @foreach (var newsYear in newsListingNode.Children) { foreach (var newsMonth in newsYear.Children) { @* Use format time to get the month string *@ dynamic dateLabel = umbraco.library.FormatDateTime(newsYear.Name + " " + newsMonth.Name + " 01", "MMMM yyyy"); <li><a href="@newsMonth.Url">@dateLabel»</a></li> } } </ul> </div> </umbraco:Macro> 

Month archive page

  <umbraco:Macro runat="server" language="cshtml"> @* Check the it is a month folder *@ @if ((@Model.NodeTypeAlias == "NewsDateFolder") && (@Model.Up().NodeTypeAlias == "NewsDateFolder") && (@Model.Up().Up().NodeTypeAlias == "NewsListing")) { dynamic newsMonth = Model; dynamic newsYear = Model.Up(); dynamic dateLabel = umbraco.library.FormatDateTime(newsYear.Name + " " + newsMonth.Name + " 01", "MMMM yyyy"); <div class="news"> <h2>News archive: @dateLabel</h2> @{ dynamic newsItems = Model.DescendantsOrSelf("NewsItem").OrderBy("sortDate desc"); } @foreach(var newsItem in newsItems) { <div class="block-content"> <h5><a href="@newsItem.Url">@newsItem.Name</a></h5> <p>@newsItem.summaryText</p> <a href="@newsItem.Url">more»</a> </div> } </div> } </umbraco:Macro> 
+6
source

The most obvious solution at Umbraco would be to arrange your folder structure in the “Content” section to match how you want the site to organize the elements and then use simple xsl transforms to create index pages.

The code of two templates (section "Settings"), one to display the index for each month, and the other to display a separate article.

So, the folder structure is like:

 > Content > |--Home > |--2011 > |--01 January > |--News article 1 > |--News article 2 > |--News article 3 > |--News article 4 > |--02 February > |--News article 5 > |--News article 6 > |--News article 7 

Then use a few simple xsl added as a macro to the index template (similar to the following) to run news articles (I got this from umbNewsListItems.xslt, which I think appeared on the newsletter site):

 <xsl:template match="/"> <!-- The fun starts here --> <div class="newsList"> <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']"> <xsl:sort select="@updateDate" order="ascending" /> <h3 class="headline"> <a href="{umbraco.library:NiceUrl(@id)}"> <xsl:value-of select="@nodeName"/> </a> </h3> <small class="meta">Posted: <xsl:value-of select="umbraco.library:LongDate(@updateDate, true(), ' - ')"/></small><br/> <p class="introduction"> <xsl:value-of select="umbraco.library:ReplaceLineBreaks(introduction)" disable-output-escaping="yes"/> </p> </xsl:for-each> </div> </xsl:template> 
+3
source

All Articles