Get Upcoming or Past Posts

Author:Scott Reilly
Version:1.0
Last update:21 April 2008
Compatibility:WP 2.2+, 2.3+ and 2.5+
Comments:go here
Download:[ zip ]
Description:

Display upcoming (today + future) or past (before today) posts in an easily customizable manner. A supplement to the Customizable Post Listings plugin.

Extended Description

Display upcoming or past posts in an easily customizable manner.

“Upcoming” is defined as a post that is published or scheduled to be published today or in the future. “Past” is defined as a post that has been published anytime prior to today. “Today” is defined as midnight (00:00:00) of the current day according to the blog’s server and current time zone.

This plugin is a supplement to the Customizable Post Listings plugin, which means that you must have the Customizable Post Listings plugin activated in order for this plugin to operate. Customizable Post Listings can be found at coffee2code.com/wp-plugins/customizable-post-listings/. You will need at least version 3.0.1 of that plugin. If CPL is not activated, the template tags provided by this plugin will simply do nothing (nothing will be displayed and no error will be triggered).

The arguments of the two provided template tags, when they match up with those for c2c_get_recent_posts() from Customizable Post Listings, are identical in usage. Please see the documentation and examples related to the Customizable Post Listings plugins to see how to use the arguments, particularly for the formatting.

NOTE: It is not recommended for future posts to use a percent-substitution tag that includes a link to that post’s permalink page (such as by using ‘%post_URL%’, ‘%post_link%’, ‘%comments_count_URL%, etc) as the permalink page for a future post won’t exist until the post’s publish date has occurred.


Installation

  1. Download the file get-upcoming-or-past-posts.zip and unzip it into your wp-content/plugins/ directory.
  2. Activate the plugin through the ‘Plugins’ admin menu in WordPress.
  3. Use the c2c_get_upcoming_posts() or c2c_get_past_posts() template tags in your template(s), as desired

Template Tags

The plugin provides two template tags for use in your theme templates.

Functions

  • Lists upcoming posts (posts published or set to be published today or in the future) :

    function c2c_get_upcoming_posts(                                                                                                   $num_posts = 5,
      $format = "<li>%post_date%: %post_title%</li>",
      $categories = '',
      $orderby = 'date',
      $order = 'ASC',
      $offset = 0,
      $date_format = 'm/d/Y',
      $authors = '',                                                                                                                             
      $post_type = 'post',
      $include_passworded_posts = false )

  • Lists past posts (posts occurring before today) :

    function c2c_get_past_posts( $num_posts = 5,
      $format = "<li>%post_date%: %post_URL%</li>",
      $categories = '',
      $orderby = 'date',
      $order = 'DESC',
      $offset = 0,
      $date_format = 'm/d/Y',
      $authors = '',
      $post_type = 'post',
      $include_passworded_posts = false )

Arguments

See the Customizable Post Listings plugin for documentation and examples related to the various arguments.

Examples

  • <ul>Upcoming Posts
      <?php c2c_get_upcoming_posts(); ?>
    </ul>

  • <ul>Past Posts
       <?php c2c_get_past_posts(); ?>
    </ul>

  • The 3 most recently upcoming posts in the events category (“34″), with custom format display:

    <dl>
       <dt>Upcoming Events</dt>
      <?php c2c_get_upcoming_posts(3, "<dd>%post_date%: %post_title%<br />%post_excerpt_short%</dd>", "34"); ?>
    </dl>


Release Log


Copyright & Disclaimer

Copyright © 2007-2008 by Scott Reilly (aka coffee2code)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


Acknowledgements

Thanks to all those who have contributed feedback and support!