Support » Plugins » Event Calendar -listing events by date of the event

  • Larry_Zins

    (@larry_zins)


    Hi, I installed the Events Calendar (7.6.8) and Event Calendar 3 (3.1.4) plugins, and discovered that there was no way to list the events by the date of the event. It lists the events by the time the post was created, which is natural for a blog. But since the website I’m developing needs to list all of the events (lectures) for the current quarter on the main page, and past quarters, I had to modify the template files in order to achieve this. So this is what I did. It appears to be working perfectly. If anyone can suggest improvements, please post. I’m using WordPress 3.0.3.

    The code is based on sample code from here:

    http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query

    Theme template: category.php:

    <?php get_header(); ?>

    <div id=”primary” class=”looped”>

    <?php pp_breadcrubs(); ?>

    <div class=”archive-info”>
    <h1 class=”page-title”><?php single_cat_title(); ?></h1>
    <?php echo category_description(); ?>
    </div>

    <?php
    //
    // Obtain the category ID number.
    //
    // See: http://codex.wordpress.org/Function_Reference/get_the_category
    //
    // To see the underlying array structure, uncomment the code below:
    //
    // global $post;
    // $categories = get_the_category($post->ID);
    // var_dump($categories);

    $category = get_the_category();
    $cat_num = $category[0]->cat_ID;

    // Custom query.

    $querystr = “SELECT wposts.*, wp_ec3_schedule.* FROM $wpdb->posts wposts inner join wp_ec3_schedule on wposts.ID = wp_ec3_schedule.post_id and wposts.post_type =’post’ and wposts.post_status=’publish’ inner join wp_term_relationships on wp_term_relationships.object_id = wposts.ID where wp_term_relationships.term_taxonomy_id='” . $cat_num . “‘ order by wp_ec3_schedule.start asc”;

    $pageposts = $wpdb->get_results($querystr, OBJECT);

    if ($pageposts):
    global $post;
    foreach ($pageposts as $post):
    setup_postdata($post);
    ?>

    <div id=”post-<?php the_ID(); ?>” <?php post_class(‘entry’); ?>>

    <h2 class=”entry-title”>” rel=”bookmark” title=”Permalink to <?php the_title(); ?>”><?php the_title(); ?></h2>

    <div class=”entry-content”>
    <?php the_post_thumbnail(‘thumbnail’);

    $date_format=get_option(‘date_format’);
    $time_format=get_option(‘time_format’);

    $date_start = mysql2date($date_format,$post->start);
    $date_end = mysql2date($date_format,$post->end);
    $time_start = mysql2date($time_format,$post->start);
    $time_end = mysql2date($time_format,$post->end);

    echo “<p>” . $date_start . ” - ” . $time_start . ” to ” . $time_end . “</p>”;
    // echo “<p>” . $post->start . ” to ” . $post->end . “</p>”;

    the_excerpt();
    ?>
    </div>
    </div><!–.entry–>

    <?php endforeach; ?>

    <?php else : ?>
    <h2 class=”center”>Not Found</h2>
    <p class=”center”>Sorry, but you are looking for something that isn’t here.</p>
    <?php include (TEMPLATEPATH . “/searchform.php”); ?>
    <?php endif; ?>

    </div><!–#primary–>

    <?php
    get_sidebar();
    get_footer();
    ?>

    Larry

Viewing 1 replies (of 1 total)
  • Hi Larry:

    The only way I can get the event listing in the order you specify and not the post date is to filter the loop using query posts:

    global $query_string;
    query_posts( $query_string . "&order=ASC" );

    1. set up a custom field called date (I used the plugin more fields) using the format yyyy/mm/dd

    2. Order by this in query posts i.e.

    global $query_string;
    query_posts( $query_string . "&meta_key=event_date&orderby=meta_value&order=ASC" );

Viewing 1 replies (of 1 total)
  • The topic ‘Event Calendar -listing events by date of the event’ is closed to new replies.