0815

Du musst dich anmelden um Beiträge und Themen zu erstellen. Einloggen · Registrieren

Display Posts for a Specified Time Period

Here is an easy way to create posts that will only be displayed for the duration of a specified time period. Replace your current loop with the following:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
	$expirationtime = get_post_custom_values('expiration');
	if (is_array($expirationtime)) {
		$expirestring = implode($expirationtime);
	}
	$secondsbetween = strtotime($expirestring)-time();
	if ($secondsbetween > 0) { ?>

		<h1><?php the_title(); ?></h1>
		<?php the_excerpt(); ?>

<?php } endwhile; endif; ?>

And then add a custom field named “expiration” to any post that needs an expiration date. For the value of the expiration key, specify the date/time in the following format: mm/dd/yyyy 00:00:00. Each post that contains such a custom field will expire after the specified date and time and will no longer appear in the loop.




0