Support » Plugins » Future Posts on a page?

  • 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 15 replies - 1 through 15 (of 26 total)
  • 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

    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. 🙂

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

    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 🙂

    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.

    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!

    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…..

    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. 🙂

    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 🙂

    Many thanks

    sk8n4s8n

    (@sk8n4s8n)

    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?

    disbas

    (@disbas)

    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.

    Thanks musik!!

    That’s I was looking for.

    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

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