Jump to:

1851 Posts in 1606 Topics by 561 members

Blog Module

SilverStripe Forums » Blog Module » Entries expires function

Discuss the Blog Module.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1156 Views
  • frabraha
    Avatar
    Community Member
    49 Posts

    Entries expires function Link to this post

    I've added an expire function for the entries so that they will not show if the date has expired. This works just fine, but I'm trying to add more function to it so that it will show entries when it comes to a date.

    But I can't get this to work..
    The code for the expiry function I got from the embargo/expire module.

    Here's what I have so far:

       function ExpiresDoNotShow() {
          if (Director::urlParam('Action') && Director::urlParam('Action') != "tag" ) {
          return true;
          }
          $now = strtotime('now');
          if($this->owner->Date && strtotime($this->owner->Date) > $now) {
             return false;
          } elseif($this->owner->DateOut && strtotime($this->owner->DateOut) < $now) {
             return false;
          } else {
              return true;
             }
       }

    If I remove else return true, nothing outputs.
    When true is set the entries that doesn't have expired shows.

    Need some help with this.

    Thanks.

  • frabraha
    Avatar
    Community Member
    49 Posts

    Re: Entries expires function Link to this post

    lol.. I feel like such a newbie..
    I've been trying to get this to work for two days now, not been able to figure out why this isn't working when the code is right.
    And I just figured out why.. I've set the in date for the entries last month, so no wonder they all show up. lol..

    So.. this is solved..

  • Lamin Barrow
    Avatar
    Community Member
    21 Posts

    Re: Entries expires function Link to this post

    I had the same problem too but mine wasn't associated with the BlogHolder. I was using custom page types and using a dataobject::get to get my custom pages in a paginated view.

    Actually, there is an easy fix to this. Instead of modifying the core code, you can just edit your BlogHolder templates files and it should work painlessly as expect.

    Like this.

    <% control BlogPosts %>
    <% if canView %>

    <!-- The Post here -->

    <% end_if %>
    <% end_control %>

    The embargo and expiring modules comes with the canView function. As you can see, you can use it in your template to filter posted based which posted get seen (you would see everything regardless of embargo or expiry restrictions if you are an admin) based on the embargo and expiry restriction.

    I hope this helps.

    Cheers
    Lamin

    1156 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.