moondawgy Posted January 10, 2011 Share Posted January 10, 2011 Always useful and a common feature - is this on the roadmap? Link to comment Share on other sites More sharing options...
ryan Posted January 12, 2011 Share Posted January 12, 2011 To unpublish by manual means (without deleting or moving the page), edit a page, click on it's 'settings' tab and uncheck the 'guest' role from the access section. There isn't a tool in the CMS to automate unpublishing by date. Though it could easily be implemented with a little API code (let me know if I can provide an example?). However, I always encourage my clients not to delete or unpublish pages if they don't have to, unless they plan to setup 301 redirects. For example, let old news items drift further down the list rather than deleting them... someone, somewhere may be linking to it. Every link to your site carries value, even if the page being linked to isn't recent. At least the user gets what they expected and can explore further in your site. Delivering a 404 page is less likely to result in that outcome. Of course, there are lots of good reasons to delete or unpublish a page, so I'm just speaking about the situations where you don't necessarily have to delete it. Another alternative to unpublishing is to enable the "hidden" status in the page editor (also on the Settings tab). A hidden page is excluded from find(), children() and siblings() results, which essentially excludes it from any of your dynamically generated navigation. It's not excluded from get() results, so the page can still be accessed by it's URL or loaded individually from the API. Link to comment Share on other sites More sharing options...
ryan Posted January 12, 2011 Share Posted January 12, 2011 moondawgy, I expanded on your question with a better answer here: http://processwire.com/talk/index.php/topic,35.0.html Link to comment Share on other sites More sharing options...
martinluff Posted January 21, 2011 Share Posted January 21, 2011 I'd add a +1 for publish/unpublish by date. For example on sites with content like job adverts (and also with other things like events/courses - although in those cases I guess you might want to use more of a dedicated calendar type arrangement) we regularly prepare a number in advance and then set a date for them in the future to go live and then auto-expire on or before the day of the course/event. I guess you could also rig up something in these sorts of cases to simply redirect to general info or overview page as they expire to avoid just getting a 404 after unpublishing if that's a concern? Link to comment Share on other sites More sharing options...
ryan Posted January 21, 2011 Share Posted January 21, 2011 I will add this to the roadmap as a module (most likely a Fieldtype). But also wanted to follow up with the strategy that I use, and the reason why the need for a publish/unpublish by date has not come up before. It's because this is so easily accomplished with the API. It also gives you more control over how you want to react to such dates. Here's how: Lets say I added a datetime field for publish date and/or expire date to the page's template. That template checks it's dates before it outputs anything. For example, lets assume we added a datetime field to the job_advert template called "expire_date". When we edited a job advert, we selected an expire_date of February 1, 2011. The job_advert template might have code like this: <?php if(time() > $page->getUnformatted('expire_date')) { throw new PageNotFoundException(); // or print "sorry this posting has expired" if you don't want a 404 } // print the job advert Note that the getUnformatted() function above is necessary because ProcessWire will return a formatted date according to the format you specified when you created the field, "January 21, 2011" as an example. So using getUnformatted() is a way to ensure it returns a timestamp that you can use for comparison with other timestamps (like that returned by PHP's time() function). (Btw, that getUnformatted() function works with any field, returning text fields without entities or runtime markup, etc.) Lets say that you also wanted to move the job advert to the trash since we now know it's expired: <?php if(time() > $page->getUnformatted('expire_date')) { $pages->trash($page); // move it to the trash throw new PageNotFoundException(); } // print the job advert Next lets assume that you didn't move the page to the trash, but you are just leaving it where it is and not disabling it or anything. If that's the case, you'll want to check that it's not expired when you links to your job adverts. So here's what your list_job_adverts template might look like: <?php $now = time(); $jobs = $page->children("expire_date>$now"); foreach($jobs as $job) { // print the job listing, being confident that it's not expired } If you had both expire_date and publish_date fields, then you'd find those jobs with something like this: <?php $now = time(); $jobs = $page->children("expire_date>$now, publish_date<=$now"); 2 Link to comment Share on other sites More sharing options...
martinluff Posted January 22, 2011 Share Posted January 22, 2011 Thanks for the response on that Ryan - yes makes a lot of sense and I see what you're getting at... guess I'm still stuck in the mindset of a few other systems Link to comment Share on other sites More sharing options...
Adam Kiss Posted January 22, 2011 Share Posted January 22, 2011 Thanks for the response on that Ryan - yes makes a lot of sense and I see what you're getting at... guess I'm still stuck in the mindset of a few other systems Don't worry, Ryan's solutions aren't always the best ;D ;D ;D Link to comment Share on other sites More sharing options...
ryan Posted January 23, 2011 Share Posted January 23, 2011 Also don't worry because I totally understand the need for a date-based publish/unpublish, and that's why it's on the roadmap. My intention was just to show a way that you could do it today if you wanted to. Also, I'm always looking for opportunities to post examples. Link to comment Share on other sites More sharing options...
Guest Posted January 30, 2011 Share Posted January 30, 2011 What if instead of just unpublishing by date there's a list presented to you somewhere for all those pages that have an expiration date so that they allow you to either unpublish, delete or update/duplicate with today's date if needed? This presents more flexibility to the admins. Here's the scenario: you have an advertisement page type that you populate with links or banners from your clients. The ad campaign could run for a month, expire and appear on such a list for you to update with a new ad. Or a set of pictures from your audience with a "Flag as inappropriate" button, once the button is pressed X times it's sent into this list for you to review and unpublish/delete. Link to comment Share on other sites More sharing options...
Adam Kiss Posted January 30, 2011 Share Posted January 30, 2011 @Rebecca: while [un-]publish by date would be a great function, anything you mentions is doable right now: if the banner is the case, just add field with dates [in] & [out] and have a little logic around it. As for second case, adding an [integer] field into your template with some js/php action should solve this right away, with no other functions needed Link to comment Share on other sites More sharing options...
Guest Posted January 31, 2011 Share Posted January 31, 2011 How would one go around presenting this to the website admins without disturbing the core with this customization that would otherwise render itself useless if/when you upgrade PW? Would you need to develop a whole new admin area inside PW separate from PW's admin area? Link to comment Share on other sites More sharing options...
Adam Kiss Posted January 31, 2011 Share Posted January 31, 2011 Rebecca: please, start a new thread into API & Templates section describing a little better what you need, and I'll be happy to oblige [and Ryan, Antti or Martin will try too, I think]. P.S.: I was talking about doing this on the template level, but you can incorporate custom modules or even whole sections into ProcessWire [that's why it's called CMS/CMF, because it's framework too], but there aren't many that advanced tutorials and I believe that Ryan is the only one who did something that advanced, so far. In any situation, please create new thread [so we don't have that many hi-jacked threads with multiple things going on], describe your problem little better [so we can help you find tailored solution] and will go from there. Link to comment Share on other sites More sharing options...
FL0RIAN Posted October 20, 2013 Share Posted October 20, 2013 <?phpif(time() > $page->getUnformatted('publish_until')) { $pages->trash($page); throw new PageNotFoundException(); } This works perfect for me with my news template. But how is it possible to do this by using the homepage template and any child page of the website, for example: homepage -news --publish until yesterday (move to trash by accessing the homepage) Thanks for your help! Link to comment Share on other sites More sharing options...
adrian Posted October 21, 2013 Share Posted October 21, 2013 if I understand you correctly you just need to get the page(s) in question first, so something like: $pagestobetrashed = $pages->find("publish_until < time()"); foreach($pagestobetrashed as $ptbt){ $pages->trash($ptbt); } Link to comment Share on other sites More sharing options...
FL0RIAN Posted October 21, 2013 Share Posted October 21, 2013 Thank you, this works for me: $ptrashed = $pages->find("template=page_events"); foreach($ptrashed as $ptrash) { if(time() > $ptrash->getUnformatted("publish_until")) { $pages->trash($ptrash); } } 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now