Jump to content

automatically remove expired news


Thomas108
 Share

Recommended Posts

Hi.

I am using the news system from this tutorial: http://wiki.processwire.com/index.php/Simple_News_System

Since the news are just short announcement for one time events, I would like to achieve the following:

I want to give the editor a field for setting an expiry date.

Expired news should automatically be removed from the main news page, but should be accessible in a folder "older entries".

I searched the forum but I didn't find anything similar.

Maybe something like this could work, but I don't know how to code this properly:

$newsposts = wire("pages")->find("parent=/news-artikel/, $category, template=news, limit=10") (CONDITION)...WHERE EXPIRY DATE FIELD IS NOT EXPIRED  

What do you think about this approach? Could it work and if so, how is this written properly?

Thanks for your help in advance.

Thomas

PS:

Here is the part from my code which fetches the news for the main news page:

$newsposts = wire("pages")->find("parent=/news-artikel/, $category, template=news, limit=10");
$out =" ";
    
foreach($newsposts as $newspost){
    $out .="<div class='newsitem'>";        
    $datum1;
    $datum1 = $newspost->publish;
  $datum1 = date("d.m.Y - H:i", $datum1);
    $out .="<a href='{$newspost->url}'><h3>{$newspost->title}</h3></a>";
    $out .="<p>{$newspost->summary}</p>";
    if($newspost->news_image){
            $out .="<a href='{$newspost->url}' class=''>";
            $out .="<img class='align_left' src='{$newspost->news_image->size(300)->url}'>";
            $out .="</a>";
        }
    $out .="</div>";
}

PSS: For the folder "older entries" I guess, I can just use the original code again.

Link to comment
Share on other sites

Thanks for all your answers.

For now I successfully implemented Andre's code.

But now I am aware of the url change.

Would be great if I could somehow create a permanent 301 redirect to the new folder "older-entries" if someone wants to open a moved entry within the old folder "news-artikel".

Any idea if this is possible?

UPDATE: Just found the Redirects module. Maybe that can help me.

Link to comment
Share on other sites

Regarding my idea of using the Redirects module, I just found out that I'll probably need a wildcard function, which is not implemented in the module.

@Adrian: The description of Page Path History sound very promising. Thanks for the link. I'll check it out.

Link to comment
Share on other sites

Why all this complicated like moving and hooking and redirecting. I think it's as simple as only display news to a certain date time expired, and have a link to older news will just show all from a certain date time backward. This could be done with a urlSegment or a physical page "older-news" that only lists, well older news. No need to go fancy complicated. News pages stay where they are, chronologically.

  • Like 4
Link to comment
Share on other sites

Not that soma's advise ever needs someone else's support, but I am in complete agreement - this approach is something I have done on several sites - it works great and saves lots of hassles and just seems more kosher.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...