Copied to clipboard

Flag this post as spam?

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


  • Erick 19 posts 89 karma points
    Oct 29, 2015 @ 11:17
    Erick
    0

    Order By Publication Date

    Hi,

    I have functionality which will allow an editor to publish items and have them displayed in date order by the published date not by the created date

    So if I have 3 items which where created on the same day but set to different publishing times as such

    Item 1 - date( 1st May 2015) Item 2 - date (1st June 2015) item 3 date (1st July 2015)

    they would display as:

    item 3 date (1st July 2015) Item 2 - date (1st June 2015) Item 1 - date( 1st May 2015)

    In order to try and achieve this I have created a custom date time picker property named publicationDate

    Code So Far

    <ul>
        @{
    
            var Nodes = Model.Content.Children();
    
           foreach (var Page in Nodes.Skip((CurrentPageNumber - 1) * PageSize).Take(PageSize).OrderByDescending(x => x.GetPropertyValue("publicationDate")))
            {
    
                if (Page.DocumentTypeAlias == "Video")
                {
                    if (Page.HasValue("heading") &&
                        Page.HasValue("posterImage"))
                    {
                        <li class="autoHeight">
                            <a href="@Page.Url">
                                <img class="autoHeight" src="@Umbraco.TypedMedia(Page.GetPropertyValue("posterImage")).Url" alt="@Page.GetPropertyValue("heading") news image" />
                                <p>
                                    @Page.GetPropertyValue("heading")                                   
                                </p>
                            </a>
                        </li>
                    }
                }
                else //treat as standard photo grid page
                {
                    if (Page.HasValue("bannerimage") &&
                        Page.HasValue("bodyTextHeading") &&
                        Page.HasValue("bannerheading"))
                    {
                        <li class="autoHeight">
                            <a href="@Page.Url">
                                <img srcset="@Page.GetCropUrl("bannerimage", "thumb")" alt="Banner Image" />
                                <p>
                                    @Page.GetPropertyValue("bannerheading")
                                    @if (Page.HasValue("subHeading"))
                                    {
                                        <br />
                                        @Page.GetPropertyValue("bodyTextHeading")
                                    }
                                </p>
                            </a>
                        </li>
                    }
                }
            }
        }
    </ul>
    

    The Main Issue

    If an editor sets any of the items to be published at a date ahead of the current date such as

    Item 4 - date( 30th Oct 2015)

    When that day approaches the item wont be automatically published

    The editor can still set the publish at date but once that item has been published it wont be displayed in the correct order since my code is setting all items by the custom publication date.

    I've done a search and cant find a way to set the publish at date, could anyone offer a way to fix this?

    One way I was looking to solve this issue was that, if the user has set the publish at date, once that date has arrived and the item has been published then set that date to my custom date property if this is possible.

    Ideally thought the best thing would be to be able to set my custom property to act the same way as the publish at date if it's set ahead of the current date and automatically publish.

    Thank for any suggestions / help

  • gary 385 posts 916 karma points
    Oct 29, 2015 @ 17:48
    gary
    0

    Hi Erick

    Umbraco has a built in property of UpdateDate, this is in fact the last publish date, but if a news item is only published once, it will remain the first published date.

    This should work on future publish, ie as soon as the node is published the UpdateDate property exists.

    Not sure if this will help you, but it may be another way of looking at what you are trying to achieve.

    Regards

    Gary

  • Erick 19 posts 89 karma points
    Oct 30, 2015 @ 14:13
    Erick
    0

    Hi Gary,

    Thanks for the suggestion, I give it a try but unfortunately it doesn't place them is the exact published date order as set in the published date property.

    Also if the editor right clicks on the parent node, selects sort and then sorts the items in either creation date or sort order etc, the nodes will get displayed in the same order, ideally I want to keep this functionality separate.

Please Sign in or register to post replies

Write your reply to:

Draft