Copied to clipboard

Flag this post as spam?

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


  • Jonathan Roberts 409 posts 1063 karma points
    Jun 02, 2016 @ 14:44
    Jonathan Roberts
    0

    Page Publish Date

    hi, I am displaying pages in a list but I want to make sure that the page is Published.

    var homePage = CurrentPage.AncestorsOrSelf(2).First();
    var menuItems = homePage.Children("vibrantNewsArticle").Where("visible");
    

    I do not want to show a page that has an Unpublish date less than today.

    I do not want to show a page that has a Publish date greater than today.

    I do not want to show a page that has not been published.

    Thanks

    Jon

  • Dennis Adolfi 1082 posts 6450 karma points MVP 6x c-trib
    Jun 02, 2016 @ 15:44
    Dennis Adolfi
    0

    Hi Jonathan.

    @homepage.Children is a list of IPublishedContent and contains published items. Umbraco handles everything with published/unpublished items server side so that you don't have to think about that in you views.

    Great right? :)

  • Dennis Adolfi 1082 posts 6450 karma points MVP 6x c-trib
    Jun 02, 2016 @ 15:46
  • Jonathan Roberts 409 posts 1063 karma points
    Jun 02, 2016 @ 15:54
    Jonathan Roberts
    0

    Hi, this is my code:

    var homePage = CurrentPage.AncestorsOrSelf(2).First();
    var menuItems = homePage.Children("vibrantNewsArticle").Where("Visible");
    
    <ul>
                @foreach (IPublishedContent job in menuItems.Where("Visible"))
                         {
                          IContent page = cs.GetById(job.Id);
    
                             <li>
                                 <div><a href="@job.Url">@job.Name</a></div>
                                                            <div>@Convert.ToDateTime(page.ExpireDate).ToString("dd/MM/yyyy")</div>
                             </li>
    
                                                }
                                            </ul>
    

    And it still shows an event that has an UnPublish Date less than today.

  • Dennis Adolfi 1082 posts 6450 karma points MVP 6x c-trib
    Jun 02, 2016 @ 16:02
    Dennis Adolfi
    0

    That sounds strange and should'nt be possible. :/ Wierd.

    Try setting a new unpublished date for the event and save. Remember to click save, and not 'Save and publish'.

  • Dennis Adolfi 1082 posts 6450 karma points MVP 6x c-trib
    Jun 03, 2016 @ 14:18
    Dennis Adolfi
    0

    Hi again Jonathan.

    Did this work out for you or are you still having trouble with this?

  • Jonathan Roberts 409 posts 1063 karma points
    Jun 03, 2016 @ 14:38
    Jonathan Roberts
    0

    Hi, it didnt work so I put my own checks around the articles. For example:

             bool canView = true;
                                                    if (page.ReleaseDate.HasValue && page.ReleaseDate > DateTime.Now)
                                                    {
                                                        canView = false;
                                                    }
    
                                                    if (page.ExpireDate.HasValue && page.ExpireDate <= DateTime.Now)
                                                    {
                                                        canView = false;
                                                    }
                                                    if (canView == true && page.Published == true){
    

    * MARK UP IN HERE }

  • Dennis Adolfi 1082 posts 6450 karma points MVP 6x c-trib
    Jun 03, 2016 @ 16:31
    Dennis Adolfi
    0

    Im sorry to hear that Jonathan! You should'nt have to do that. Maybe you should report this issue along with the version number to http://issues.umbraco.org?

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies