Jump to content

Publishdate Module


Philipp Nowinski
 Share

Recommended Posts

Hey Folks,

I created a module that adds a publish_date field to every page. It basically is an extended version of the code the community came up with in this thread: https://processwire.com/talk/topic/2448-show-date-published-on-a-page

It's available on GitHub: https://github.com/kaesetoast/processwire-publish-date

Let me know what you think of it :-)

  • Like 6
Link to comment
Share on other sites

Thanks for this - looks great.

What do you think about the situation where a page is published, then unpublished, and then published again. I think your current behaviour is probably fine, but just wanted to see if anyone else has any thoughts on whether the initial date should be preserved or not?

What about including a published_users_id as well? This actually brings me back to Nico's suggestion of calling the field "published". That way we'd have:

created

created_users_id

modified

modified_users_id

published

published_users_id

Actually, any thoughts about whether it would be better to extend the pages database table to include these fields directly, rather than as separate custom fields? Maybe that's not a good idea for some reason I haven't thought of yet - anyone have any thoughts on this? 

  • Like 3
Link to comment
Share on other sites

Adrian - you could take it further and use a custom fieldtype and hide it. This would give you a custom table able to store all publishes and un-publishes to every page and just requires a column for date, user and action (pub or un-pub).

But then we're into more of a user action history module instead and I think there's already a module for that?

That was totally not what you were asking though ;)

Link to comment
Share on other sites

.....What do you think about the situation where a page is published, then unpublished, and then published again. I think your current behaviour is probably fine, but just wanted to see if anyone else has any thoughts on whether the initial date should be preserved or not?........... 

I'd go for not. In Blog I'll go for not (when I get round to it :-)). Otherwise, we get into guessing why a page was unpublished in the first place territory - (1). Initial publish was done in error OR (2). Client wants to temporarily make a page inaccessible from the frontend OR..... 

  • Like 1
Link to comment
Share on other sites

I would just use the first publish date. Because if you have a blog and order by published you want to have the post stay at the same position

Good point...for Blog I'll go for preserve then unless there is a compelling counter-thought?

@Philipp: Sorry to mess up your thread ...Oh, and welcome to PW and the forums... :-)

Link to comment
Share on other sites

For the publish-unpublish-republish scenario you could also make it configurable via a "retain publish date when unpublished" option? Because i can see cases for both.

Yeah, was mulling this...The option would work best at page level, no? i.e., one may not want this to apply universally....Could be tedious though at page level...

Link to comment
Share on other sites

Hey guys,

wow - I did not expect the community to be that active.. One reason more to love PW :-)

Thanks for all the suggestions. I like the idea of reducing the field name to 'publish'. Seems a lot more consistent.

I'm not sure about this publish-unpublis-publish scenario. I guess the only situation where you would want the publish date to change is when you published by accident. Making this optional could work, but it should be on page level then. At least I would not want this behaviour for all pages. And yes, that could definitely be tedious..

What about simply making the publish field visible and editable? It is hidden by default (if created by the module), but that can be changed easily. That way you could simply change or reset the publish date if you hit the button too early.

  • Like 3
Link to comment
Share on other sites

Hey guys,

wow - I did not expect the community to be that active.. One reason more to love PW :-)

.......

I'm not sure about this publish-unpublis-publish scenario. I guess the only situation where you would want the publish date to change is when you published by accident. Making this optional could work, but it should be on page level then. At least I would not want this behaviour for all pages. And yes, that could definitely be tedious..

.........

I haven't tested the module but looking at the code you are aware that the way it is now, the publish date get's emptied when you 'unpublish' (via the relevant Status checkbox) a page? When republishing it get's populated with the current time, in fact changing the original publish date.

This seems to be in contrast to your thoughts in the above quote, unless i am misunderstanding you.

Thinking a bit more about this subject i begin to wonder if this shouldn't be something available in core. I know there's already the SchedulePages module, but if you think about it there are quite a lot of use-cases for scheduled content and it probably wouldn't be that big of a deal adding it (but maybe i'm wrong ;) )

So if you just go publish a page via the corresponding button it sets the status to published but also sets a field like 'publish_from' with a default of time(), and a field like publish_until with default empty.

If you wanted to 'schedule' the page you would need to go to the settings page where you could maybe pick the dates via date pickers for publish_from and publish_until.

Link to comment
Share on other sites

I haven't tested the module but looking at the code you are aware that the way it is now, the publish date get's emptied when you 'unpublish' (via the relevant Status checkbox) a page? When republishing it get's populated with the current time, in fact changing the original publish date.

This seems to be in contrast to your thoughts in the above quote, unless i am misunderstanding you.

Ahh, damn, you are right. I actually did not think about this when creating the module. I'm not quite sure about what I like better, clearing the field on unpublish, or keeping the first-publish timestamp. My first thought was that it's always better to keep the data and overwrite it if necessary, than loosing it by accident. With this in mind I would tend to change the current behaviour of the module. I'm wondering what I would expect here as the user. Maybe this depends on which usecase is more common: publishing by accident, or using the unpublish function to hide a page.

Any other thoughts about this?

Link to comment
Share on other sites

Just to throw an additional thought into the mix. I think this is a great addition, but in some cases I will still want to add an additional "published_date" field to my page. This would most likely be for printed documents where I am hosting a collection of PDF reports etc and where the date of publication may not match the day the item is published on a PW site, which is a very common scenario. I think "published_date" is distinct from published since the latter is a datetime field and for a printed doc PDF etc all you need is the date.

Link to comment
Share on other sites

Hmm.. So there may be conflicts with sites that already have a field that uses the same name as my module. Maybe I should make the fieldname configurable. I guess the fixed name would be fine for a core module, but since this is something you might want to throw into an existing application, it might be a sensible addition.

  • Like 1
Link to comment
Share on other sites

  • 2 months later...

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