Jump to content
Thomas108

automatically remove expired news

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.

Share this post


Link to post
Share on other sites

There is the Schedule Pages module....for auto-expiring...but not moving... :-)...but you can achieve that with a simple module/hook. But Date Archiver looks like it will do what you want...

Edited by kongondo

Share this post


Link to post
Share on other sites
Something like this should work:

$newsposts = $pages->find("parent=/news-artikel, expiry_date<".time());

foreach($newsposts as $newspost){

 $newspost->parent = "/older-entries";

 $newspost->save();

}

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Enable the core module "Page Path History" and it will take care of the redirects for you.

  • Like 1

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

@soma: yep, uncomplicated sounds good.

But I never used url segments before, so lets see...

Tomorrow I'll check the different post about url segments.

Have a nice evening.

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...