WordPress.org

Ready to get started?Download WordPress

Forums

Future Posts on a page? (27 posts)

  1. rforster
    Member
    Posted 5 years ago #

    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!

  2. MichaelH
    Member
    Posted 5 years ago #

    Could use this plugin http://wordpress.org/extend/plugins/the-future-is-now/

    PHP-exec is a plugin that allows you to put PHP code in a post (or page) and then that code is executed like any ohter PHP code. Otto also has a plugin that allows you to put PHP code in a Widget.

    You can also put code in a template.

    Stepping Into Templates
    Template Hierarchy

  3. rforster
    Member
    Posted 5 years ago #

    Thanks Michael. I grabbed that snippet of code from:
    http://comox.textdrive.com/pipermail/wp-hackers/2007-November/016104.html

    Not sure why it didn't click that it would be part of a plugin. At least I tried to make it work. :)

  4. MichaelH
    Member
    Posted 5 years ago #

    I believe that was a 'precursor' to the final code that ended up in that plugin.

  5. musik
    Member
    Posted 5 years ago #

    I've installed that plugin, and the future dated posts do appear under the Archives menu but do not appear on the calendar.. any ideas on what to change to allow the posts dated for future times to appear in the calendar?

    Am using it as an events calendar also.

    Cheers :)

  6. MichaelH
    Member
    Posted 5 years ago #

  7. musik
    Member
    Posted 5 years ago #

    Thanks Michael, I've tried that plugin and it doesn't work very well for what I want.

    With the 'Future is Now' installed I can get the future posts to show in the sidebar under 'Archives' as a link under the month it falls into, but it refuses to show up in the calendar in the sidebar.

  8. rforster
    Member
    Posted 5 years ago #

    I'm writing a piece of code that will display a list of future events. Here's what I have done and want to do:
    I made a category called Events.
    I made a page called Events.
    Have php-exec plugin installed.
    Have cludged together the folowing:

    $query = "select * from wp_posts
    order by post_date desc limit 20";

    This works with some other statements. So it is selecting all of the fields in records from the posts table. Nice. I need the "where" statement worked out:

    $query = select * from wp_posts
    Where post_date is greater than yesterday
    and category is equal to "Events"
    order by post_date asc limit 20";

    I've tried a few where statements involving dates but they either fail or get 0 events.
    Also, I don't see where the "post_category" field does anything. I went into phpMyAdmin and this field has all zeros. Just dont know how this works.

    I'll post the code commented nicely when I get these statements worked out.

    Thanks!

  9. rforster
    Member
    Posted 5 years ago #

    Here's the part to get a date one less than today:
    where post_date > NOW()+0 -1000000
    or where post_date > NOW()

    The first gets the current date and time, converts it to a number and subracts and amount so the day is one less than today. This really gets you any event (Post) that was done yesterday at the current time. Example:
    Create a post for a car show in the events category with a start time of 8:00. Doesn't really matter what the end time is but in the content portion you could make note.

    The "where post_date > NOW()" will give you everything that hasn't happened yet. Example: The car show example above this would be a bad way to write this line as when someone visits the page at 8:30 the NOW() will be greater than post_date so it wouldn't show on you page.

    I'll figure out how to subtract everything from the current time back to midnight. Really just preference for the types of events you might have.

    Now how do we pull the "events" category.....

  10. musik
    Member
    Posted 5 years ago #

    OK! I've solved my problem of future posts not showing up on the sidebar calendar and here is how. You will still need to install 'The Future Is Now' plugin. http://wordpress.org/extend/plugins/the-future-is-now/

    Activate it in your Plugin settings on your dashboard.

    Now open general-template.php which is found in the folder wp-includes

    Go to Line 639 or thereabouts... Or look for the following code;

    // Get days with posts
    
                    $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
    
                                    FROM $wpdb->posts WHERE MONTH(post_date) = '$thismonth'
    
                                    AND YEAR(post_date) = '$thisyear'
    
                                    AND post_type = 'post' AND post_status = 'publish'
    
                                    AND post_date < '" . current_time('mysql') . '\'', ARRAY_N);

    Change it to;

    // Get days with posts
    
                    $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
    
                                    FROM $wpdb->posts WHERE MONTH(post_date) = '$thismonth'
    
                                    AND YEAR(post_date) = '$thisyear'
    
                                    AND post_type = 'post' AND post_status = 'publish' "
    
                                    /*AND post_date < '" . current_time('mysql') . '\''*/, ARRAY_N);

    When you create your new future posts change the Publish Status to 'Published' and select the date your event/gig etc is on. Now your calendar will show future date posts. :)

  11. flick
    Member
    Posted 5 years ago #

    I was actually wondering what the change was, but they I realised it's commenting out the line:

    AND post_date < '" . current_time('mysql') . '\''

    Nice solution :)

  12. jzo
    Member
    Posted 5 years ago #

    Many thanks

  13. sk8n4s8n
    Member
    Posted 5 years ago #

    Looks like musik's solution is what I'm in need of, but I cannot overwrite general-template.php on my server, I've changed the files permissions too.. any suggestions?

  14. disbas
    Member
    Posted 5 years ago #

    I took a different approach to get a list of upcoming events (using the future is now-plugin).

    <?php query_posts('cat=5&posts_per_page=5&orderby=date&order=ASC'); ?>
    <?php while ( have_posts() ) : the_post() ?> <!--loop-->
    
    <?php  //check the dates
    $post_date = mysql2date("Ymd", $post->post_date_gmt);
    $currentdate = date("Ymd", strtotime('-1 day'));
    $expirationdate = $post_date;
    if ( $expirationdate > $currentdate ) { ?>
    
    <!-- add your html here -->
    
    <?php } //end date check ?>
    <?php endwhile ?><!-- end loop -->

    The code returns a list of the next 5 events in category 5 (i.e. events). Todays events are listed as well because of the strtotime.

    No need to change any of the core files. Just put this code in your sidebar to get upcoming events.

  15. benialvarez
    Member
    Posted 5 years ago #

    Thanks musik!!

    That's I was looking for.

  16. tades
    Member
    Posted 5 years ago #

    Disbas and Musik, are you using wordpress 2.3, 2.5.1 or 2.6?. those hacks don't works on WP 2.6 or 2.5.1...

    Thanks

  17. disbas
    Member
    Posted 5 years ago #

    I'm using them on 2.6.5.

  18. tades
    Member
    Posted 5 years ago #

    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();
    ?>
  19. disbas
    Member
    Posted 5 years ago #

    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();
    ?>
  20. tades
    Member
    Posted 5 years ago #

    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

  21. disbas
    Member
    Posted 5 years ago #

    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.

  22. tades
    Member
    Posted 5 years ago #

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

    thanks a lot

  23. Cristiano
    Member
    Posted 5 years ago #

    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!!

  24. Cristiano
    Member
    Posted 5 years ago #

    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!!

  25. Cristiano
    Member
    Posted 5 years ago #

    Forgot to say I´m using WP 2.7!

  26. Cristiano
    Member
    Posted 5 years ago #

    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; ?>
  27. Cristiano
    Member
    Posted 5 years ago #

    Is happening the same with Tades...

Topic Closed

This topic has been closed to new replies.

About this Topic