In this video, we’ll put it all together and walk through an example of how to use scheduler to automatically publish and unpublish an image in an image slideshow.
Now that we’ve got an understanding of how Scheduler works, let’s take a look at how we can use it in conjunction with a homepage slideshow.
In the Views Slideshow series, we saw how to create an image slideshow and I’ve set one up here following the steps in that series. If you’d like more information on using Views Slideshow, take a look at that series.
Let’s pretend we’ve got an event coming up next Friday, and we’d like to promote that event on our homepage starting Monday morning, and stop promoting it at midnight on Saturday after the event has happened. We can create the slide now, and have Scheduler automatically publish and unpublish the slide at the appropriate times.
Allowing featured content to be scheduled
I’ve already setup a content type called “Featured Content”. Let’s Edit that content type and allow it to be published and unpublished using Scheduler.
- Go to “Structure => Content types => Featured Content” (admin/structure/types/manage/featured-content)
- Click the “Scheduler settings” vertical tab
- [x] Enable scheduled publishing
- [x] Alter published on time
- [x] Enable scheduled unpublishing
- (Save content type)
Now, all we need to do is create a new slide, enter the details of the event, upload the image and schedule its publish and unpublish dates.
Creating the featured content slide
- Go to “Content => Add content => Featured Content” (node/add/featured-content)
- Title: Party!
- Image: (upload image)
- Scheduling settings: (I’m going to enter times that are just a few minutes from now, instead of waiting days for this to publish.)
- Publish on (date)
- Unpublish on (date)
- (Save)
Seeing it publish and unpublish
Now all we have to do is wait for cron to run after the “publish date”, and the image will be included in the slide show!
...
Now that it’s after the time we set for the slide to publish, I’ll run cron manually to see the slide.
And there it is!
Now, I’ll wait until after the “unpublish on” date, and run cron again to see it automatically unpublish itself.
...
Now you see that the slide has gone. We can also check the content page to see that the content is still on the site, even though it is unpublished.
- Go to “Content” (admin/content)
Here, we see the content, and that its status is “unpublished”.
There you go! I hope this example is enough to show you the capabilities of Scheduler and how you can utilize it in your projects!