Jump to content

publish date


Marty Walker
 Share

Recommended Posts

Currently there isn't a way to change the published 'created' date, short of changing it directly in the SQL. PW only sets this field the first time a page is saved, and then doesn't include it in any future saves. Though I could certainly change that. But if you are working this weekend, here's how you could do it with SQL:

<?php

$page = $pages->get("/page/you/want/to/change/"); 
$time = strtotime("2011-04-23"); // or whatever date you want

wire('db')->query("UPDATE pages SET created=$time WHERE id={$page->id}"); 
  • Like 1
Link to comment
Share on other sites

Is there a way to approach this by using a custom date field and sorting by that field? And if that's possible can I also add pages with a date in the future that won't appear in the foreach results until that day. I know I could approach this part of the site by using WP or textpattern but it's not an intensive part of the site to warrant that.

Regards

Martin

Link to comment
Share on other sites

Absolutely--You could definitely use a custom date field for this. And if you don't want them showing in foreach, then just specify a date range in your selector:

$today = time();
foreach($page->children("date<$today") {
   ...
}
Link to comment
Share on other sites

Thanks Ryan. Would I use it like this? Still learning this php lingo :)

<?
$today = time();
echo "<dl class='notes-list'>";
$notes = $pages->get("/notes/")->find("template=notes, sort=-publish_date");
foreach($notes as $note("date < $today")) {
	echo "<dt>{$note->title}<time pubdate>{$note->publish_date}</time></dt>";
	echo "<dd>{$note->summary}<a class='read-more' href='{$note->url}'>→ read</a></dd>";
}
echo "</dl>";
Link to comment
Share on other sites

I'm on a cell phone so some of your code example isn't coming through but put your publish_date selector in here:

$notes = $pages->get("/notes/")->children("template=notes, sort=-publish_date, publish_date<$today");

Link to comment
Share on other sites

Just a quick note that might be of some use to somebody, I'm also looking at a publish_date field for a project for things like news articles and other pages as well as an unpublish_date field (think pages that are very time-sensitive and don't apply after a given date) - just a few other scenarios worth considering there.

Are these two things something that might make it into the core further down the line ryan or is this something that would be best suited to a module? I'm only thinking the core as they're fields that appear in quite a lot of other systems, though there's certainly no reason why they couldn't be included in a module instead.

Link to comment
Share on other sites

I have actually had similar need in almost every site. If you use date field to manage "when it is published", then you have to be very careful with each of your selectors (so that ie: you don't show unpublished stuff on your "latest edited pages on whole site" list or something).

It feels like pretty generic need to be able to say something like "hidden from all search and lists when current date < publish_date", It would be great to be shown as hidden also on pagelists. Of course it would be pretty simple cron module to check that and publish pages when publish date has passed, but not the most elegant way of handling this?

Link to comment
Share on other sites

Currently there isn't a way to change the published 'created' date, short of changing it directly in the SQL. PW only sets this field the first time a page is saved, and then doesn't include it in any future saves. Though I could certainly change that.

Better have an additional "modified" date field.

Link to comment
Share on other sites

  • 3 months later...

Sorry to drag this up again.

I have a "publish_date" field setup with input set to d-m-Y (European/Australian), user date picker checked. I can select and set a date fine. If I go to change that date the picker date defaults to a US format.

Eg: If i set my date in the picker as 10 Dec 2011 (1-11-2011) and then go to change it afterwards the picker displays (Jan 11 2011).

Am I missing something?

Regards

Marty

Link to comment
Share on other sites

I don't have access to my computer just now, but if I recall it correctly there is a note about this when you have the date picker selected. Something like that it will be changed to your output format when saving the page.

Is this what you meant?

/Jasper

Link to comment
Share on other sites

I think what you experience is what we got in this thread http://processwire.com/talk/index.php/topic,558.0.html

It's basicly the problem that the jquery ui datapicker date format isn't compatible with php date format. I spent some time to do a mapping array for converting (as you see at the end of the thread) , but ryan hasn't implemented it yet. I think it would work with simple dates, but not for times. I'm not sure how well this can be implemented for datetime fields and datepicker with time select addon).

Link to comment
Share on other sites

  • 5 years later...
On 04/09/2011 at 4:34 AM, ryan said:

Absolutely--You could definitely use a custom date field for this. And if you don't want them showing in foreach, then just specify a date range in your selector:


$today = time();
foreach($page->children("date<$today") {
   ...
}
 

Think I'm gonna need something like this for listing posts by date, thanks @ryan

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...