Copied to clipboard

Flag this post as spam?

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


  • Robert 63 posts 282 karma points
    Sep 08, 2014 @ 14:29
    Robert
    0

    Ordering by publishDate

    Hi,

    I have a question on a topic i started earlier (that was solved).

    Related topic: Click

    When we have a new news-item with an image it will be displayed on top so that is good. But when we make a new news-item with an image that is earlier uploaded so it has an older upload date for the image, that news-item will not be on top.

    I would like to have control over the items so we have an publishDate that must sort the items and not the create date from the images. Some one that could change that please?

    This is the whole Partial View:

    @inherits UmbracoTemplatePage
    @using System.Globalization
    @{
    
    // If the editor has not explicitly provided the "Page title" property page 
    // then just show the name of the page otherwise show the provided title
    var pageTitle = string.IsNullOrWhiteSpace(CurrentPage.Title)
        ? CurrentPage.Name
        : CurrentPage.Title;
    
    // Model.Content is the current page that we're on
    // AncestorsOrSelf is all of the ancestors this page has in the tree
    // (1) means: go up to level 1 and stop looking for more ancestors when you get there
    // First() gets the first ancestor found (the home page, on level 1)
    var homePage = CurrentPage.AncestorsOrSelf(1).First();    
    
    // Find all pages with document type alias umbNewsOverview
    // We do that using the plural, umbNewsOverviews (note the extra "s" in the end)
    // Then take the first one, as we know there will only be on news overview page
    var newsOverview = homePage.umbNewsOverviews.First();
    
    // Similar to above: find all pages with document type umbNewsItem under the news overview page
    // Then order them, first by publishDate (a property the editor can explicitly set on the news item)
    // and then by createDate, which is set by Umbraco automatically when a page gets created.
    var newsItems = newsOverview.umbNewsItems.OrderBy("publishDate desc, createDate desc").Take(4);
    
    bool containsImages = newsItems.Where("image != String.Empty").Count() > 0 ? true : false;
    
    var featuredNews = containsImages ? (Umbraco.Web.Models.DynamicPublishedContent)newsItems.OrderBy("image desc").First() : null;
    var otherNews = newsItems;
    
    if (containsImages && featuredNews != null)
    {
        var featuredNewsId = featuredNews.Id;
    
        if(featuredNewsId > 0)
        {
            var values = new Dictionary<string, object>();
            values.Add("excludenode", featuredNewsId);
    
            otherNews = newsItems.Where("Id != excludenode", values);
        }
    }
    }
    

    Fontend mark-up

    <div class="col-md-6 col-sm-6">
    <div class="HomeBlock4">
        <div class="col-md-6 col-xs-6 npl">
            <h2>Algemeen</h2>
        </div>
        <div class="col-md-6 col-xs-6 npr">
            <a href="/nieuws-algemeen/">
                <div class="NewsArchiveLink pull-right">
                    Nieuws archief
                </div>
            </a>
        </div>
    </div>
    <div class="HomeBlockContent">
        <div class="rowpad col-md-12">
            <ul>
                @if (containsImages && featuredNews != null)
                {
                    var featuredNewsTitle = string.IsNullOrWhiteSpace(featuredNews.GetPropertyValue("title").ToString()) ? featuredNews.Name : featuredNews.GetPropertyValue("title").ToString();
                    var featuredNewsText = featuredNews.GetPropertyValue("bodyText").ToString();
                    var featuredNewsImage = featuredNews.GetPropertyValue("image");
                    var featuredNewsTextTruncated = Umbraco.Truncate(featuredNewsText, 100, true, false);
    
                    <li>
                        <div class="imageItemHeight">
                            <div class="col-md-4 col-xs-4 npl">
                                <a href="@featuredNews.Url">
                                    <div class="NewsHomeImageDiv">
                                        <img src="/ImageGen.ashx?image=@featuredNewsImage&Compression=100&width=100&height=100&constrain=true">
                                    </div>
                                </a>
                            </div>
                            <div class="npr WordBreak">
                                <h3><a href="@featuredNews.Url">@Umbraco.Truncate(featuredNewsTitle, 57, true, false)</a></h3>
                                @Umbraco.StripHtml(featuredNewsTextTruncated)
                            </div>
                        </div>
                    </li>
                }
                <div class="newsMargin">
                @foreach (var newsItem in otherNews)
                {
    
                    // If the editor has not explicitly provided the "Page title" property page 
                    // then just show the name of the page otherwise show the provided title
                    var title = string.IsNullOrWhiteSpace(newsItem.Title) ? newsItem.Name : newsItem.Title;
    
                    // If the editor has not explicitly set the publishDate property then show the create date
                    var dateTime = newsItem.PublishDate == default(DateTime) ? newsItem.CreateDate : newsItem.PublishDate;
                    <div class="row npl npr">
                        <div class="HomeNewsItem">
                            <li>
                                <article class="is-post-summary WordBreak">
                                    <div class="rowpad col-md-12">             
                                        <h3>
                                            <img src="../Css/VVEemdijk/images/ItemImage.png" height="7" width="4" class="HomeNewsItemArrow">
                                            <a href="@newsItem.Url">@Umbraco.Truncate(title, 41, true, false)</a>
                                            <div class="NewsItemDate">@dateTime.ToString("f", CultureInfo.CreateSpecificCulture("nl"))</div>
                                        </h3>
                                    </div>
                                </article>
                            </li>
                        </div>
                    </div>
                }
                </div>
            </ul>
        </div>
    </div>
    </div>
    

    Kind regards,

    Robert

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Sep 09, 2014 @ 10:29
    Ismail Mayat
    0

    Robert,

    That does not sound right, regardless of how old the image is you have explicitily set the sort to by news item publishdate and createdate.  Can you do quick experiment, create new news item DO NOT SELECT AN IMAGE and note down after publishing the publish date and create date. Then select an older image and publish then check the create date, is that date updated? Report findings.

    Regards

    Ismail

  • Robert 63 posts 282 karma points
    Sep 09, 2014 @ 10:59
    Robert
    0

    Hi Ismail,

    Thanks for your reply!

    I make a new one without an image and publish it: createDate newsitem: 2014-09-09 10:53:29 Then i add an image and: createDate newsitem: 2014-09-09 10:53:29

    EDIT: the publishDate is empty by default.

    Regards, Robert

Please Sign in or register to post replies

Write your reply to:

Draft