Custom Start Date / End Date

6 posts by 3 authors in: Forums > CMS Builder
Last Post: July 11, 2012   (RSS)

By wevolutions - July 7, 2012

I have regular listings that I show on my website but I wish to have certain listings being "featured" in another page for a specified time period.

I know about the publishDate features but I want to be able to use a custom field (eg. start_date) in order to manually input the desired time period. I noticed that when I used the publishDate option, all my regular listings just disappear.

What is the best way to set this up? I created a checkbox named "featured_ad" so that once I check this option, it will be displayed based on the manual date that I enter.

Re: [Jason] Custom Start Date / End Date

Hi Jason, you are correct. I want the regular listings to always remain but I also want some featured listings to be shown from time to time.

I need assistance in getting the coding to do this.

I want to have a "Start Date" and an "End Date" for the featured listings which I will input manually.

How do I input the code to use the dates as I mentioned above and also to implement the checkbox for the featured listings?

Re: [WEVOLUTIONS] Custom Start Date / End Date

By Jason - July 11, 2012

Hi,

If you want to use start and end dates to define if a record is featured or not, you won't need the check box.

Here is an untested example of some code to detect if a given record is featured or not while outputting your event records:

EXAMPLE:
<?php $currentDateTime = time(); ?>
<?php foreach ($myEvents as $event): ?>

<?php if (strtotime($event['start_date']) <= $currentDateTime && strtotime($event['end_date']) >= $currentDateTime): ?>
//event is featured
<?php else: ?>
//event is not featured
<?php endif ?>

<?php endforeach ?>


Hope this helps get you started
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Custom Start Date / End Date

Hi Jason, thank you for your response. I don't think this is what I have in mind.

Here is what I need basically:

1. I have a checkbox named "featured_ad".
2. I have a Start Date named "featuredStartDate".
3. I have an End Date named "featuredEndDate".

I want to display all listings that are checked and which have the Start Date and End Date manually inputted. The listings will show only for this specified time period and then not display anymore.

I can't make this any simpler. I hope this helps. Thank you.

Re: [WEVOLUTIONS] Custom Start Date / End Date

By gkornbluth - July 11, 2012

Hi Wevolutions,

I haven't tried it out but I think the code that Jason gave you is almost what you want.

Could you wrap the date compare in an if that checks for the value of your checkbox and get rid of the else?
<?php $currentDateTime = time(); ?>
<?php foreach ($myEvents as $event): ?>
<?php if ($record['featured_ad']==1): ?>
<?php if (strtotime($event['featured_start_date']) <= $currentDateTime && strtotime($event['featured_end_date']) >= $currentDateTime): ?>
//event is featured code
<?php endif ?>
<?php endif ?>

<?php endforeach ?>


If you want to list the event earlier then the start date or to include the day of the end date you can easily adjust the date checking code. There are a number of recipes on dates and times in my CMSB Cookbook at thecmsbcookbook.com

Just a thought...

Jerry Kornbluth

.
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php