Michael van Laar Posted August 10, 2015 Share Posted August 10, 2015 I’m just building my new blog with processwire. Regarding the publish date of an article I’d like to have the same functionality WordPress provides. My idea: I include the “Publish From Date“ field of the Schedule Pages module in my template. I use the “Publish From Date“ field in my frontend templates to display the publishing date of an article and to sort articles chronologically. When writing a new article, I’d like to have two options:If I want to schedule the publishing of an article, I fill the “Publish From Date“ field with the desired date and time. If I want to publish a new article instantly, I leave the “Publish From Date“ field empty and simply click the “Publish” button. In this case right after publishing – or even better before the publishing workflow step is finished – a page with an empty “Publish From Date“ field, the “Publish From Date“ field should be filled with the current timestamp automatically. Otherwise no publishing date could be displayed in the frontend and the article couldn’t be sorted as latest one correctly. Is there an easy way to achieve this auto-filling of the “Publish From Date“ field when publishing a page? I guess I have to hook into anything to achieve that. I have not worked with PW hooks by now, so my knowledge of hooks is very limited. But I couldn’t find anything “publish” related in the PW hooks cheatsheet. Of course I could simply fill the “Publish From Date“ field manually even if I want to publish the page instantly. But I’d like to use this functionality for other blogs, too – with editors who are used to the publish date field auto-filling like WordPress does it. Link to comment Share on other sites More sharing options...
kongondo Posted August 10, 2015 Share Posted August 10, 2015 Maybe how we do it in the Blog Module can be of help. Have a look at the Hooks here. 3 Link to comment Share on other sites More sharing options...
Michael van Laar Posted August 11, 2015 Author Share Posted August 11, 2015 Great advice! Thanks a lot Link to comment Share on other sites More sharing options...
Juergen Posted August 11, 2015 Share Posted August 11, 2015 This is the simple way how to include all your hooks after page save: https://processwire-recipes.com/recipes/extending-page-save-process/ Link to comment Share on other sites More sharing options...
Peter Knight Posted August 11, 2015 Share Posted August 11, 2015 Don't date/time fields have the option to default to the current time/date. That's how I handle it and then manually set it if required. 1 Link to comment Share on other sites More sharing options...
Michael van Laar Posted August 11, 2015 Author Share Posted August 11, 2015 Don't date/time fields have the option to default to the current time/date. That's how I handle it and then manually set it if required. Yes, date/time fields have this option. But since the publish_from field is part of the “Schedule Pages” module, this would result in not being able to save a new article without publishing at all. That’s why I implemented Kongondo’s solution today. Link to comment Share on other sites More sharing options...
Michael van Laar Posted August 11, 2015 Author Share Posted August 11, 2015 Maybe how we do it in the Blog Module can be of help. Have a look at the Hooks here. Works like a charm. I made minimal modifications to make it work without the rest of the Blog Module: https://github.com/MichaelvanLaar/PW-AutofillPublishFromDate My version of the module simply does its job for every page which has a publish_from field which is installed with the Schedule Pages module. 2 Link to comment Share on other sites More sharing options...
Michael van Laar Posted August 11, 2015 Author Share Posted August 11, 2015 Because I think that this should be a feature of the Shedule Pages module, I forked the module, added an option (so that this feature can be turned on optionally) and made a pull request: https://github.com/formmailer/SchedulePages/pull/8 2 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