Adding end date to post?
-
Hi,
I would like to add an “end date” to my posts, since my posts are displayed as events.
For example:
Event starts on 5th of May.
Event ends on 6th of July.Right now I can only select one date; the date I want to publish my post on.
Is it possible to either change the code in the template or download a plugin to make an end date?
I have already been searching everywhere for a solution, but I cannot find an answer. Any help will be appreciated!
-
Thank you – but I am not exactly sure how to use it.
Here is my index.php.
Where do I paste the code and and am I supposed to make new custom fields to make it work?I’m not that good at coding, sorry 🙁
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”EN” lang=”EN”><?php get_header(); ?>
<body>
<div class=”main”>
<div class=”container”>
<div class=”span-24 header”>
<h1 class=”name”>“><?php bloginfo(‘name’); ?><!–<span class=”bubble”><img src=”<?php bloginfo(‘stylesheet_directory’); ?>/img/<?php echo $bubbles; ?>” alt=”bubbles” /></span>–></h1>
<span class=”slogan”><?php bloginfo(‘description’); ?></span>
</div><?php include (TEMPLATEPATH . “/navigation.php”); ?>
<div class=”span-24 content”>
<div class=”span-16 post-wrapper”>
<?php if (is_category(28)) { ?>
<h1>Art</h1>
<?php } else { ?>
<h1>Cal</h1>
<?php } ?><?php
if (is_home()) {
query_posts(“cat=-28”);
}
?>- “, “html_wrap_close” => “
- “, “html_wrap_close” => “
<?php if (have_posts()) : ?>
<?php
//based on Austin Matzko’s code from wp-hackers email list
function filter_where($where = ”) {
//posts in the coming days
$where .= ” AND post_date > ‘” . date(‘Y-m-d’, strtotime(‘+0 days’)) .”‘”;
return $where;
}
add_filter(‘posts_where’, ‘filter_where’);
query_posts($query_string . “&order=ASC”);
?><?php while (have_posts()) : the_post(); ?>
<li class=”post”>
<div class=”text-header”>
<div class=”hr”><img src=”<?php bloginfo(‘stylesheet_directory’); ?>/img/<?php echo $scissors; ?>” alt=”scissors” /></div><h2 class=”title”> ” title=”Permanent Link to <?php the_title_attribute(); ?>”> <?php the_time(‘d M //’) ?> <?php the_title(); ?> </h2>
<span class=”no”> ” title=”Permanent Link to <?php the_title_attribute(); ?>”> <?php comments_number(‘Skriv en kommentar’, ‘1 kommentar’, ‘% kommentarer’); ?></span>
<div class=”clear”></div></div>
<div class=”info-small”>
<span class=”author”> Skrevet af:
<?php the_author_posts_link(); ?></p></span><span class=”cat”>
<?php the_category(‘, ‘) ?></span>
</div><?php the_content(‘Læs mere.. »’); ?>
<?php echo ‘<ul class=”addtoany_list”>’;
if( function_exists(‘ADDTOANY_SHARE_SAVE_ICONS’) )
ADDTOANY_SHARE_SAVE_ICONS( array(“html_wrap_open” => ”“) );
if( function_exists(‘ADDTOANY_SHARE_SAVE_BUTTON’) )
ADDTOANY_SHARE_SAVE_BUTTON( array(“html_wrap_open” => ”“) );
echo ‘‘; ?>
<?php the_meta(); ?>
<div class=”clear”></div>
<?php the_tags(‘<span class=”tag small”> Tags: ‘, ‘, ‘, ‘</span>’); ?>
<?php edit_post_link(‘Edit’, ‘<p class=”edit”>’, ‘</p>’); ?><?php endwhile; ?>
<?php else : ?>- <p><h2>Ikke fundet indlæg</h2></p>
<p>Der er endnu ikke skrevet indlæg for denne måned.</p>
<?php endif; ?>
<li class=”post”>
<p class=”alignright calendar-forward”><?php next_posts_link(‘» Se længere frem i kalenderen’) ?></p>
<p class=”alignleft calendar-back”><?php previous_posts_link(‘« Gå tilbage’) ?></p></div>
<div class=”span-8 last sidebar”>
<?php get_sidebar(); ?>
</div>
</div><?php get_footer(); ?>
</div>
</div></body>
</html>Forget that code then. Create a custom field for start date or end date (or both) when writing posts.
Then in your code above the_meta() will cause those custom fields to be displayed.
Related:
Custom FieldsYes the custom field will be displayed – that’s not the problem.
As you might have noticed I use the code below.
<?php if (have_posts()) : ?>
<?php
//based on Austin Matzko’s code from wp-hackers email list
function filter_where($where = ”) {
//posts in the coming days
$where .= ” AND post_date > ‘” . date(‘Y-m-d’, strtotime(‘+0 days’)) .”‘”;
return $where;
}
add_filter(‘posts_where’, ‘filter_where’);
query_posts($query_string . “&order=ASC”);
?>When using the code you have to publish the post on the day the event ends – for else the post will not be showed, when the current date is over.
For example if I publish a post about an art exhibition, I choose to publish the post two weeks ago – because the exhibition runs for two weeks – for example on May 15th. And the post will be displayed on the website, as long as I post it today or some date in the future (+0 days like the code says). BUT the problem is that people might not notice that the art exhibition runs before they scroll down to May 15th and then it’s too late for them to go to the art exhibition.
So what I need is an extra feature that will display the post during the period it is active. If I publish a post in june and the event is also active in may and june, the post will only be displayed if you click on the month of june on my website.
I would be nice to have a feature that makes you choose when a post starts and when a posts end. The custom fields are not interacting with the actually publish date. It only shows some fields.
I hope you know what I mean?
maybe irrelevant by now, but instead of using greater than ‘>’, use greater or equal to ‘>=’ to show on the final date.
The topic ‘Adding end date to post?’ is closed to new replies.