Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Brendon Bauer

macrumors 6502
Original poster
May 14, 2007
344
0
Good 'ol USofA
Is this possible:

To place, say, paragraph A on an html page. At the same time, paragraph B is in the html but is hidden. At time X, paragraph A is replaced with paragraph B. Basically, I'd just update this each week in the middle of the week so that over the weekend at a set time the paragraph would update without me having to be around to do it. That way I can have a consistent update time period.

Anyone know if this is possible?

Thanks!
Brendon
 
Wordpress has this option. It's a time stamp that won't get published until a certain time. It certainly doesn't hide anything, it just doesn't release it from the database to be posted until that time is valid.
 
I suppose I could set up a whole different wordpress system for this, but it seems like a lot of work for something really simple. I only need a couple of things showing up at once... It's basically just a "what's happening this week" and "what's happening next week" paragraph that gets updated each week. Is there a slightly more simple script I could use?

You can see what I'm working with at the bottom of this page: http://www.summitnorthwest.org/
 
Well, HTML wasn't really setup for this type of thing, but it can be done, though not the prettiest thing you ever saw. Here's a solution in PHP.

PHP:
<?php
$paras = array(
  '20080211' => '<p>stuff1.</p>',
  '20080219' => '<p>stuff2.</p>',
  '20080226' => '<p>stuff3.</p>');
$today = date("Ymd");
foreach ($paras as $key => $para) {
  if ($key <= $today) {
    print $para;
  }
}
?>
I use an associative array with the key setup to a date in YYYYMMDD format and the value is whatever HTML will be displayed for that day. Then I get today in the same date format. Then stepping through each array element I check if the key (the date) is earlier or equal to today it will be printed. I'm not exactly sure what you're doing but you could probably tweak this code to fit your needs. You may be after switching the if statement to greater than so it shows upcoming dates.
 
What would I change in that script to make it so that once stuff2 is displayed, stuff1 disappears. I want stuff2 to replace stuff1 as soon as the date rolls around. Is that possible?

Thanks! That's almost what I'm looking for.
 
What would I change in that script to make it so that once stuff2 is displayed, stuff1 disappears. I want stuff2 to replace stuff1 as soon as the date rolls around. Is that possible?

Thanks! That's almost what I'm looking for.

OK, think I'm understanding what you want better. This is a touch simpler.

PHP:
$currentContent = '<p>stuff1.</p>';
$newContent = '<p>stuff2.</p>';
$changeDate = '20080220';
$today = date("Ymd");
if ($today >= $changeDate) print $newContent;
else print $currentContent;
 
What I ended up doing was using the first script you gave me and modifying it for my needs. Instead of using dates, I used the week of the year function. Also, I made it so that if today was a sunday, it was part of the next week of the year because I wanted the weeks to begin on sunday (so my script would be updated on saturday night at midnight).

PHP:
<?php 
$paras = array( 
  '07' => '<p>stuff0.</p>',
  '08' => '<p>stuff1.</p>', 
  '09' => '<p>stuff2.</p>', 
  '10' => '<p>stuff3.</p>'); 
$today = date("W");
// The number below represents which day of the week begins a new week. By default a new week begins on Monday, but we wanted the script to update Saturday night at midnight (on Sunday) instead of Sunday night at midnight (on Monday) we use a 0. 0 = Sunday, 6 = Saturday. Because we put in 0, the script will update as soon as 12:01 Sunday arrives. If we want the script to update on Wednesday at midnight, we'd use a 4 instead.
if (date("w") == 0) {
	$myday = $today+1;
	$today = str_pad($myday,2,'0',str_pad_left);
}
$nextweek = strtotime("+1 week");
$nextweek = date('W',$nextweek);
// Same goes for the number below as well.
if (date("w") == 0) {
	$mydaynextweek = $nextweek+1;
	$nextweek = str_pad($mydaynextweek,2,'0',str_pad_left);
}
foreach ($paras as $key => $para) { 
  if ($today == $key) { 
    print $para; 
  }
}
// Insert some HTML code in here with the echo command to have something between your two messages that are shown.
foreach ($paras as $key => $para) { 
  if ($nextweek == $key) { 
    print $para; 
  }
} 
?>

This worked better than the simplified version because I want to enter stuff months in advance. Also, I have it set up so it nicely fits in my formatting. I also needed to place html code between the two messages that would show at once. Basically, I have a section that shows "This week" and "next week" headings with the appropriate information shown below. You can see it in action at the bottom of the page at http://www.summitnorthwest.org.
 
Cool, I'm glad my code was able to get you in the right direction. I figured the first code snippet would be better if you had more date points.

I briefly looked at your source code on that page, and there's a number of problems. For one, there's like 3 <html> tags and a couple DOCTYPE declarations, though none at the top where it's suppose to go. I recommend using a validator and cleaning up the code a bit and making it more valid. I'm very surprised browsers are able to display it. No offense, just letting you know.
 
To be honest, it's because I'm stuck using dreamweaver... I really don't like dreamweaver but the site began by using a simple dreamweaver template and it has all those stupid "uneditable regions" and whatnot because of the template. I'd really like to just make it a phpinclude at the top and use Coda instead. I have a tough time with dreamweaver because it's clunky and I always just find myself doing stuff so that it displays right. I feel like it's going to be a huge project validating everything :\ . It's going to be hard to get it out of dreamweaver though... Thanks for the tips though, no offense taken :).
 
Ah, DreamWeaver templates. It all makes sense now. It just surprised me since you obviously know how to program, given your solution, that the HTML code would be that way, but those templates can suck. I tried using them once, but started pulling out my hair soon after.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.