• Hi everyone,

    Have been doing some searching in regards to making a list of upcoming events. Been looking at full calendar solutions but for now just making a post and editing the date and time is fine. I found a snippet of code:
    *************
    <?php
    /*
    Plugin Name: The Future is Now!
    Description: Display posts with a timestamp in the future.
    Version: R1.0.1
    */
    function show_future_where($where) {
    global $wpdb;
    if( !is_single() && !is_page() )
    $where .= ” OR $wpdb->posts.post_status = ‘future’ “;
    return $where;
    }
    add_filter(‘posts_where’, ‘show_future_where’);
    ?>
    **********
    I’m running php-exec and put this on a page called events(imagine that). Should I be putting this on a template instead? Haven’t tried making a template yet on my own.

    Any help would be great!

Viewing 11 replies - 16 through 26 (of 26 total)
  • I’m using them on 2.6.5.

    Disbas, I test your code in WP 2.6.3, and now future post appear, but the old posts appear also, not only future posts.

    can you tell me what is my bug?

    I put your code in category page

    my code

    <?php
    
      get_header();
    
      if (have_posts()): ?>
    
      <ol id="posts"><?php query_posts('cat=3&posts_per_page=10&orderby=date&order=ASC'); ?>
    <?php while ( have_posts() ) : the_post() ?> 
    
        <li class="postWrapper" id="post-<?php the_ID(); ?>">
    
          <h2 class="postTitle"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
          <small><?php the_date(); ?> by <?php the_author(); ?></small>
    
          <div class="post"><?php the_content(__('(more...)')); ?></div>
          <p class="postMeta">Category: <?php the_category(', ') . " " . the_tags(__('Tags: '), ', ', ' | ') . comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)')) . edit_post_link(__('Edit'), ' | '); ?></p>
    
          <hr class="noCss" />
        </li>
    
        <?php comments_template(); // Get wp-comments.php template ?>
    
    <?php  //check the dates
    $post_date = mysql2date("Ymd", $post->post_date_gmt);
    $currentdate = date("Ymd", strtotime('-1 day'));
    $expirationdate = $post_date;
    if ( $expirationdate > $currentdate ) { ?>
    
    <?php } //end date check ?>
        <?php endwhile; ?>
    
      </ol>
    
    <?php else: ?>
    
      <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    
    <?php
    
      endif;
      ?>
    
      <?php if (will_paginate()): ?>
    
        <ul id="pagination">
          <li class="previous"><?php posts_nav_link('','','&laquo; Previous Entries') ?></li>
          <li class="future"><?php posts_nav_link('','Next Entries &raquo;','') ?></li>
        </ul>
    
      <?php endif; ?>
    
      <?php
      get_footer();
    ?>

    Well, it looks as if your checking the dates too late. First check if there is a post. If so, check the date. Then do the html.

    I did some reshuffling in your code. Didn’t test it, though.

    <?php
    
      get_header();
    
      if (have_posts()): ?>
    
      <ol id="posts"><?php query_posts('cat=3&posts_per_page=10&orderby=date&order=ASC'); ?>
    <?php while ( have_posts() ) : the_post() ?> 
    
    <?php  //check the dates
    $post_date = mysql2date("Ymd", $post->post_date_gmt);
    $currentdate = date("Ymd", strtotime('-1 day'));
    $expirationdate = $post_date;
    if ( $expirationdate > $currentdate ) { ?>
    
        <li class="postWrapper" id="post-<?php the_ID(); ?>">
    
          <h2 class="postTitle"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
          <small><?php the_date(); ?> by <?php the_author(); ?></small>
    
          <div class="post"><?php the_content(__('(more...)')); ?></div>
          <p class="postMeta">Category: <?php the_category(', ') . " " . the_tags(__('Tags: '), ', ', ' | ') . comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)')) . edit_post_link(__('Edit'), ' | '); ?></p>
    
          <hr class="noCss" />
        </li>
    
        <?php comments_template(); // Get wp-comments.php template ?>
    
    <?php } //end date check ?>
        <?php endwhile; ?>
    
      </ol>
    
    <?php else: ?>
    
      <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    
    <?php
    
      endif;
      ?>
    
      <?php if (will_paginate()): ?>
    
        <ul id="pagination">
          <li class="previous"><?php posts_nav_link('','','&laquo; Previous Entries') ?></li>
          <li class="future"><?php posts_nav_link('','Next Entries &raquo;','') ?></li>
        </ul>
    
      <?php endif; ?>
    
      <?php
      get_footer();
    ?>

    Disbas

    your tips are greats. Thanks a lot. I put this (&posts_per_page=15) for display posts, but always show 7. Why?.

    I changed value post_per_page=-1 for display full post, but don’t works also.

    post_per_page=-1 (link)

    thanks again

    Slightly going off topic now: did you check the number of posts in settings > read? Else try ‘showposts=-1’ instead. If that doesn’t work, best start a new thread.

    you right, I set the number posts… but don’t works, I’ll try another thread.

    thanks a lot

    Dibas, thanks for your code, i′m using it and it′s almost perfect for me! The problem is that the post navigation got confused… i underestand what is happening, but I can′t realize how to solve it, any help would be great!
    ( I hope I can explaint it well, my english is poor! ??

    The problem:
    I have like 12 posts to be showed after de “future date” filter. My setup it to show 10 posts on the homepage, but it just show one on the first page, but give you the choice to “navigate” to the second page, where there is 10 posts…

    What I think is happening:
    I think the problem is that the “check date” is after the “check post”, so the loop recognize the old posts, and althought they aren′t showed, the system considers it. I really have 9 old posts!

    I tryed to change the “check date” place, but I couln′t get it working!

    Any help???
    Thanks!!

    Dibas, thanks for your code, i′m using it and it′s almost perfect for me! The problem is that the post navigation got confused… i underestand what is happening, but I can′t realize how to solve it, any help would be great!
    ( I hope I can explaint it well, my english is poor! ??

    The problem:
    I have like 12 posts to be showed after de “future date” filter. My setup it to show 10 posts on the homepage, but it just show one on the first page, but give you the choice to “navigate” to the second page, where there is 10 posts…

    What I think is happening:
    I think the problem is that the “check date” is after the “check post”, so the loop recognize the old posts, and althought they aren′t showed, the system considers it. I really have 9 old posts!

    I tryed to change the “check date” place, but I couln′t get it working!

    Any help???
    Thanks!!

    Forgot to say I′m using WP 2.7!

    The code, a little bi modified, to get little improvement of the filter:

    <?php query_posts($query_string . "&order=ASC"); ?>
    	<?php $prev_date ='0'; ?>
    
    	<?php if (have_posts()) : ?>
    	<?php while (have_posts()) : the_post(); ?>
    
            <?php  //check the dates
    
    		$post_date = mysql2date("Ymd", $post->post_date_gmt);
    		$currentdate = date("Ymd", strtotime('-1 day'));
    		$limitdate = date("Ymd", strtotime("next Monday"));
    		$expirationdate = $post_date;
    
    			if ( $expirationdate > $currentdate && $expirationdate < $limitdate) { ?>
    
    		<div class="Post" id="post-<?php the_ID(); ?>" style="padding-bottom: 40px;">
    
    			<div class="PostHead">
    			<h1><a title="Permanent Link to <?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h1>
    				<small class="PostLocal">en <?php the_category(', ') ?>
                    	<small class="PostEdit"><?php edit_post_link('Edit'); ?></small><br />
                    	<small class="PostTags"><?php the_tags('', ', ', '<br />'); ?></small>
                        <small class="PostTags"><?php the_time('g:i a'); ?></small>
                	</small>
    
                       		<?php  //posts on same date
    						if ( $post_date != $prev_date ) { ?>
    
    						<p class="PostDate">
    						<small class="day"><?php the_time('j') ?></small>
    						<small class="month"><?php the_time('M') ?></small>
    						<small class="year"><? // php the_time('Y') ?></small>
    						</p>
    
                            <?php $prev_date = $post_date; ?>
                            <?php } //end same date check ?>
    
    			</div>
    
    			<div class="PostContent">
    			<?php the_content('Leer m&aacute;s...'); ?>
    			</div>
    
    			<div class="PostDet">
     				<li class="PostCom"><?php comments_popup_link('0 Comentarios', '1 Comentario', '% Comentarios'); ?></li>
    			</div>
    
    		</div>
    
    		<!-- <?php trackback_rdf(); ?> -->
    		<div class="clearer"></div>
    
    		<?php } //end date check ?>
    
    		<?php endwhile; ?>
    
    	  <?php if (will_paginate()): ?>
    
        <ul id="pagination">
          <li class="previous"><?php posts_nav_link('','','&laquo; Previous Entries') ?></li>
          <li class="future"><?php posts_nav_link('','Next Entries &raquo;','') ?></li>
        </ul>
    
      <?php endif; ?>
    
    			<?php else : ?>
    			<h2><?php _e('Vacio'); ?></h2>
    			<p><?php _e('Perdona, no hay ninguno evento con esos criterios.'); ?></p>
    
    	<?php endif; ?>

    Is happening the same with Tades…

Viewing 11 replies - 16 through 26 (of 26 total)
  • The topic ‘Future Posts on a page?’ is closed to new replies.