showing special by day of week
2 posts by 2 authors in: Forums > CMS Builder
Last Post: February 25, 2011 (RSS)
By rez - February 25, 2011
I have a list (checkboxes) manually made in one editor with Monday, Tuesday, Wednesday, etc.
I am simply trying to show the special for today by day name like this (or a better way of course, in the top of the page instead?):
Which is not working. Thats probably an easy fix but I also have two more problems with this:
1. Not sure how to show specials that are on multiple days. (Monday, Wednesday) Looping through an array or something? I'm clueless with that.
2. Not sure now to handle a special that is every other Saturday. ?! I looked into the custom strartotime and followed the link to php.net in the field options. I'm guessing the answer is something to do with this but i dont know how to say every other saturday and if i did, not sure how that would work in the same editor as the other specials.
hopefully, i'm over complicating this.
thanks for any help.
I am simply trying to show the special for today by day name like this (or a better way of course, in the top of the page instead?):
<?php foreach ($weekly_specialsRecords as $record): ?>
<?php if (date("l") == $record['when']): ?>
<?php echo $record['title'] ?><br/>
<?php endif ?>
<?php endforeach ?>
Which is not working. Thats probably an easy fix but I also have two more problems with this:
1. Not sure how to show specials that are on multiple days. (Monday, Wednesday) Looping through an array or something? I'm clueless with that.
2. Not sure now to handle a special that is every other Saturday. ?! I looked into the custom strartotime and followed the link to php.net in the field options. I'm guessing the answer is something to do with this but i dont know how to say every other saturday and if i did, not sure how that would work in the same editor as the other specials.
hopefully, i'm over complicating this.
thanks for any help.
Re: [rez] showing special by day of week
By Jason - February 25, 2011
Hi,
Since "when" is a multi-value list separated by tab (\t) characters, we first need to break it up into an array. Try using this code:
Setting something to happen every other Saturday is much more complex because you would need to keep track of which day the product was last displayed.
There are a couple of simpler ways to get this would be to:
a) just turn off that check box every other week
b) have a date field where you set the next date the special is to appear.
Hope this helps.
Since "when" is a multi-value list separated by tab (\t) characters, we first need to break it up into an array. Try using this code:
<?php $today = date("l"); ?>
<?php foreach ($weekly_specialsRecords as $record): ?>
<?php $days = explode( "\t", trim( $record['when'], "\t" ) ); ?>
<?php if ( in_array( $today, $days ) ): ?>
<?php echo $record['title'] ?><br/>
<?php endif ?>
<?php endforeach ?>
Setting something to happen every other Saturday is much more complex because you would need to keep track of which day the product was last displayed.
There are a couple of simpler ways to get this would be to:
a) just turn off that check box every other week
b) have a date field where you set the next date the special is to appear.
Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/