Copied to clipboard

Flag this post as spam?

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


  • trfletch 598 posts 604 karma points
    Mar 30, 2010 @ 16:56
    trfletch
    0

    Display news items by month created

    Hi,

    I have an Umbraco V4 website and I want to create a news list that is displayed by month for example I have the following structure:

    News
        - Article 1        *created 23rd February 2010*
        - Article 2        *created 2nd February 2010*
        - Article 3        *created 15th January 2010*
        - Article 4        *created 5th January 2010*
        - Article 5        *created 10th December 2009*

    When you view the news page I want it to display the latest months news then have a drop down menu so people can view previous months news, the catch is that the past month may not yet have any news added so I only want it show the most recent month that does have news, like in the example above there is no news for March therefore when you view the news page I want it to show February's news. I have created many news lists before but I am struggling as to where to start with this one because of the filter by month scenario and would appreciate it if anyone can point me in the right direction. Let me know if you need me to explain it more. I basically want it to look like this:

     

    News

    February    **this shows the most recent month that has any news articles**

    Article 1    **this is a link to the article**

    Article 2    **this is a link to the article**

     

    View news from [Select month]  **this is a drop down box that lists all the months that have news articles and selecting it filters the month that is shown above**

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Mar 30, 2010 @ 17:27
    Dirk De Grave
    1

    I'd seriously consider using AutoFolders or DateFolders project as this will greatly simplify your solution.

     

    Hope this helps.

    Regards,

    /Dirk

  • Dan 1288 posts 3921 karma points c-trib
    Mar 30, 2010 @ 17:34
    Dan
    0

    Perhaps this will help:

    http://our.umbraco.org/forum/developers/xslt/8098-Get-property-of-sibling-within-loop - it's the XSLT approach I used to tackle the problem.

  • Kim Andersen 1447 posts 2196 karma points MVP
    Mar 30, 2010 @ 17:49
    Kim Andersen
    1

    Just like Dirk says, I'd use the AutoFolders package. This package almost does the trick for you. And you will not only be able to get your news sorted into months, but also into years. It's a great package, and especially for this type of issues.

    /Kim A

  • trfletch 598 posts 604 karma points
    Mar 30, 2010 @ 18:15
    trfletch
    0

    Thanks for the responses guys, I will have a look at Autofolders which looks like the one that should meet my needs. I will post back if I have any problems.

  • trfletch 598 posts 604 karma points
    Mar 30, 2010 @ 18:28
    trfletch
    0

    I've realised something that could be an issue with this. I assume these packages sort the data into folder by created date? This will be a problem because for one I am creating a Umbraco version of a site that already exists so I will have to recreate old news articles and they will all have a recent date even though they could be months old. The other issue along the same lines is that the end user will want to create news items for February in March (they might be a bit slow uploading items). Is there a way the folders can be sorted by a property of the news article that is date picker?

  • Tommy Poulsen 514 posts 708 karma points
    Mar 30, 2010 @ 18:51
    Tommy Poulsen
    0

    Hi, I think I would investigate the possibilities of using xslt keys and ids for this - using the Munchean method.

    As I understand it you want to show months that actually contains data.

    Check out this article for info and example: http://blackpoint.dk/umbraco-workbench.aspx?Snippet=/umbraco-workbench/xslt/grouping--distinct-values.aspx

    >Tommy

  • Daniel Horn 319 posts 344 karma points
    Mar 30, 2010 @ 21:17
    Daniel Horn
    1

    You have to run the news not on createDate but define a date on the documenttype which the news shall be from.

    Then use autofolders for sorting them and http://our.umbraco.org/projects/cmsimport for importing the old news (or are they already in Umbraco?) 

    Rest is XSLT

    I would do it that way :-)

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 30, 2010 @ 23:45
    Jan Skovgaard
    0

    I second to what Daniel is suggesting. In your case you can't rely on @createDate. The best way to go is to define a datefield, in which you can control how your news items are sorted etc.

    In the matter of publishing news on a certain date you can use the "Publication Status" on the "property" tab. Here you can set a date, at which the news item should be published and when it should be unpublished. But please be aware that this might be buggy in 4.0.3 in some cases. Can't remember if it has already been solved in this version though.

    Another option is to make a check to see if the date you have selected with your custom date property is met in your for-each loop. In that way only news from todays date or greater can be showed allowing you to add news that should not right away.

    /Jan

  • trfletch 598 posts 604 karma points
    Mar 31, 2010 @ 11:40
    trfletch
    0

    Hi,

    Thanks for the responses, Daniel that is exactly what I want to do, I want the document type to have a date picker field called something like "Week Ending" then I want the Autofolders to sort the news articles based on this field. The question is how do I do this? Am I going to have to modify the source code (hopefully not because my asp.net is quite limited)?

  • Daniel Horn 319 posts 344 karma points
    Mar 31, 2010 @ 11:50
    Daniel Horn
    0

    Hi again,

    It's not so complicated, add a "weekEnding" property to your document type with a date picker.

    In your autofolder settings you then define that you are going to sort the news with that property "weekEnding" 

    <property alias="DateField">weekEnding</property>

    Is that enough to get you going? :-)

  • trfletch 598 posts 604 karma points
    Mar 31, 2010 @ 12:11
    trfletch
    0

    I was hoping it was that easy! Ok we'll I haven't actually mananged to get Autofolders working yet, I have installed the package but so far it is not sorting my folders. I will have a little play and post back if I get stuck. Thank you for all your help.

  • trfletch 598 posts 604 karma points
    Mar 31, 2010 @ 12:59
    trfletch
    0

    Ok I have been trying for a while and I cannot get this to work, I am getting all sorts of funny errors such as when I try and publish the news article I get Object reference not set to an instance of an object

    I have installed the package, I have got a document type that has an alias of "Newsarticle" and it has a date picker field that has an alias of "weekEnding". These pages are created under a document type called News Section. I have copied over the contents of the bin folder from the Umbraco 4.0.3 install that contains the hotfix relating to the date picker property. I have the following in my autofolders config file. Can anyone see what I am doing wrong? Do I have to create a document type called "DateFolder"? I was under the impression that this was a default folder in Umbraco?

    <?xml version="1.0" encoding="utf-8" ?>
    <settings>
      <folderProviders>
      <folderProvider alias="DateFolderProviderNews"
                assembly="/bin/AutoFolders"
                type="AutoFolders.Providers.DateFolderProvider">
           <property alias="MonthFormat">MMMM</property>
           <property alias="YearFormat">yyyy</property>
              <property alias="DateField">weekEnding</property>
         </folderProvider>
      </folderProviders>
     <autoFolders>
      <autoFolder docType="Newsarticle"
                 folderProviderAlias="DateFolderProviderNews"
                 folderDocType="DateFolder"
                 />
    </autoFolders>

    </settings>
  • trfletch 598 posts 604 karma points
    Apr 01, 2010 @ 13:42
    trfletch
    0

    Has anyone got any ideas on this issue? I get the following error when I try and save and publish a News article and I have selected a date from the "Week ending" date picker. If I do not select a date then I can save and publish without any problems. This is the error I receive:

     

    Server Error in '/' Application.

    --------------------------------------------------------------------------------

     

    Object reference not set to an instance of an object. 

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

     

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

     

    Source Error: 

     

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

     

    Stack Trace: 

     

     

    [NullReferenceException: Object reference not set to an instance of an object.]

       umbraco.cms.businesslogic.Content.CreateContent(ContentType ct) +118

       umbraco.cms.businesslogic.web.Document.MakeNew(String Name, DocumentType dct, User u, Int32 ParentId) +387

       AutoFolders.Providers.DateFolderProvider.CreateFolderStructure(Document newDocument, Int32 iNodeRootFolder, String folderDocTypeAlias) +392

       AutoFolders.ApplicationBase.Document_New(Document sender, Object e) +174

       umbraco.cms.businesslogic.web.Document.FireAfterPublish(PublishEventArgs e) +27

       umbraco.cms.businesslogic.web.Document.PublishWithResult(User u) +1109

       umbraco.cms.presentation.editContent.Publish(Object sender, EventArgs e) +177

       System.EventHandler.Invoke(Object sender, EventArgs e) +0

       umbraco.controls.ContentControl.savePublish(Object Sender, ImageClickEventArgs e) +46

       System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) +108

       System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) +118

       System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10

       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13

       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36

       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

     

     

  • Daniel Horn 319 posts 344 karma points
    Apr 01, 2010 @ 17:25
    Daniel Horn
    0

    My head is to tired today to go through code and errors :(.

    What about installing http://our.umbraco.org/projects/business-website-starter-pack , Dan Drayne has made his news section just as you want, but without autofolders - but you could add autofolders to it or just check out how it is done? :)

  • Dan 1288 posts 3921 karma points c-trib
    Apr 01, 2010 @ 17:46
    Dan
    0

    Sorry you're having so many issues trfletch.  I faced a similar scenario a couple of weeks ago where I needed clients to be able to add news articles into the CMS and have them display on the website under year/month headings, so you'd get:

    2010

    January

    Article header 1

    Article header 2

    February

    Article header 3

    Article header 4

    March

    Etc etc etc

     

    I wasn't aware of the datefolder or sortfolder packages at the time, but I created my own system very easily by just having the client create year folders and month folders in the CMS, and then add articles to them.  I didn't go down to day level as it was overkill for the number of articles they have and the admin overhead in creating so many folders manually.  That made it very simple for them to manage, they could go backwards and add old articles, and it also made it very simple to display the articles on the site - under only the months/years available.  It was a simple bit of XSLT to group the results by month (which I posted in my link earlier).

    I could give you more detail if you're interested, or perhaps I've got the wrong end of the stick and you're looking to do something very different?  Let me know if I can be of use anyhow...

  • trfletch 598 posts 604 karma points
    Apr 01, 2010 @ 18:32
    trfletch
    0

    Hi Dan,

    Thanks for the response, the method you described is my last resort if I do not get Autofolders to working but I really want this to be automatic so the Umbraco user doesn't have to manually create the Month folders, partly because it is a extra step for them and partly because they could make a mistake when typing the name of the folder.

    Also I have other sites that could benefit for using Autofolders because users have complained that they would like the nodes to be sorted either into alphabetical or date folders to make it easy to manage when there are a lot of nodes under one folder therefore I am really eager to get this working.

Please Sign in or register to post replies

Write your reply to:

Draft