Copied to clipboard

Flag this post as spam?

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


  • randy 7 posts 87 karma points
    Oct 18, 2021 @ 20:11
    randy
    0

    I'm fairly new to Umbraco and inherited a client's website built by a different agency. I am having problems with a Template that is not working properly. The website has a "Latest News" page that is supposed to list news releases in chronological order. In the staging environment, there is a date function that can let me set the news release posting date. However, even if I set the date in the staging environment, the live site lists all postings with one date: 01/01/01.

    Any suggestions on a fix?

  • Nik 1591 posts 7148 karma points MVP 6x c-trib
    Oct 18, 2021 @ 20:29
    Nik
    0

    Hi Randy,

    Unfortunately without seeing what the code looks like in your template/controller it's hard to gauge what the problem could be. There are lots of reasons for why the date might not be showing or why the sorting might not be working correctly.

    Are you able to share more?

    Thanks

    Nik

  • randy 7 posts 87 karma points
    Oct 18, 2021 @ 20:37
    randy
    0

    Here is the code:

    @inherits UmbracoViewPage

    @{ Layout = "masterPage.cshtml";

    var itemParent = Model.AncestorOrSelf<NewsListingPage>();
    var items = itemParent.Children<NewsYear>();
    
    int yearSelected = -1;
    bool first = true;
    bool newsArticle = false;
    

    }

    Media Center

            <div class="tabs-content">
    
                <div class="media--pressreleases content active" id="panel1-1">
                    <h2>News</h2>
    
                    <ul class="media--nav-year no-bullet" id="nav2">
                        @foreach (var item in items)
                        {
                            string classNm = "";
    
                            if (item.Id == Model.Id
                                || (first && Model.Id == itemParent.Id)
                                || item.Id == Model.Parent.Id)
                            {
    
                                yearSelected = item.Id;
                                first = false;
    
                                classNm = "active";
                            }
    
                            if (item.Id == Model.Parent.Id)
                            {
                                newsArticle = true;
                            }
                            <li class="@classNm"><a href="@item.Url()">@item.Name</a></li>
                        }
    
                    </ul>
    
                    <div class="media--main">
    
                        @if (newsArticle)
                        {
                            var article = Model as NewsArticlePage;
    
                            <div class="date">
                                <span class="day">@article.PublishedDate.ToString("dd")</span>
                                <span class="month">@article.PublishedDate.ToString("MMM")</span>
                                <span class="year">@article.PublishedDate.ToString("yy")</span>
                            </div>
    
                            <div class="article">
                                <h3>@article.PageTitle</h3>
                                <p class="description">@article.BodyContent</p>
                            </div>
                        }
                        else
                        {
                            var listParent = yearSelected == -1 ? itemParent : Umbraco.Content(yearSelected);
                            var listItems = listParent.Children<NewsArticlePage>().OrderByDescending(x => x.PublishedDate);
    
                            foreach (var item in listItems)
                            {
                                <ul class="2014 media--main--list no-bullet">
                                    <li class="clearfix">
    
                                        <div class="date">
                                            <span class="day">@item.PublishedDate.ToString("dd")</span>
                                            <span class="month">@item.PublishedDate.ToString("MMM")</span>
                                            <span class="year">'@item.PublishedDate.ToString("yy")</span>
                                        </div>
    
                                        <div class="article">
                                            @if (item.Link != null)
                                            {
                                                <h3><a href="@item.Link.Url" target="@item.Link.Target" class="title">@item.DisplayTitle</a></h3>
                                                <p class="description">@item.Synopsis</p>
                                                if(item.Link.Url.IndexOf("pdf") > -1) {
                                                    <a href="@item.Link.Url" target="@item.Link.Target" class="more"><i class="icon_pdf icon"></i> View Article</a>
                                                } else {
                                                    <a href="@item.Link.Url" target="@item.Link.Target" class="more">Read more »</a>
                                                }
                                            } else {
                                                <h3><a href="@item.Url()" class="title">@item.DisplayTitle</a></h3>
                                                <p class="description">@item.Synopsis</p>
                                                <a href="@item.Url()" class="more">Read more »</a>
                                            }
                                        </div>
                                    </li>
                                </ul>
                            }
                        }
    
                    </div>
                </div>
    
                <div class="media--inthenews content " id="panel1-2"></div>
                <div class="media--events content" id="panel1-3"></div>
    
            </div>
        </div>
    </div>
    

  • Nik 1591 posts 7148 karma points MVP 6x c-trib
    Oct 18, 2021 @ 21:42
    Nik
    0

    Hi Randy,

    Is PublishedDate a property that has been added to your NewsArticlePage doc type? If so, can you confirm it's data type?

    Thanks

    Nik

  • randy 7 posts 87 karma points
    Oct 19, 2021 @ 08:03
    randy
    0

    Hi Nik,

    Data type is Date Picker.

    Thanks, Randy

  • Nik 1591 posts 7148 karma points MVP 6x c-trib
    Oct 19, 2021 @ 08:53
    Nik
    0

    This may seem silly, but have you confirmed that the articles have legitimate published dates set?

  • randy 7 posts 87 karma points
    Oct 19, 2021 @ 23:19
    randy
    0

    Yes, confirmed legit published dates. Plus I posted a new article and reposted old articles, but the date stamp still does not reflect the correct date.

Please Sign in or register to post replies

Write your reply to:

Draft