WordPress.org

Ready to get started?Download WordPress

Forums

Events Archive with Monthly Headers (3 posts)

  1. nadine00
    Member
    Posted 1 year ago #

    Hi,

    I have this code for an events listing, and I was wondering if there's a way to re-work some of it so that its organized by month with a monthly header.

    So for example:

    February
    - event
    - event
    January
    - event
    - event

    Thanks!

    <?php
    
    	$upevent = array(
    	'post_type' => 'events',
    	'meta_key' => 'tf_events_startdate',
    	'orderby' => 'meta_value',
    	'order' => 'DESC',
    	'posts_per_page' => -1
    
    	);?>
    
    	<ul>
    
    	<?php query_posts($upevent); ?>
    	<?php if (have_posts()) : while (have_posts()) : the_post();?>
    
    	<?php
    		$custom = get_post_custom(get_the_ID());
    
    		// dates
    		$sd = $custom["tf_events_startdate"][0];
    		$ed = $custom["tf_events_enddate"][0];
    
    		// - local time format -
    		$time_format = get_option('time_format');
    		$stime = date($time_format, $sd);
    		$etime = date($time_format, $ed);
    
    	?>
    
    			<?php // - determine if it's a new day -
    			$longdate = date("l, M j, Y", $sd);
    			if ($daycheck == null) { echo $longdate; }
    			if ($daycheck != $longdate && $daycheck != null) { echo $longdate; } ?>
    			<br />
    			<?php echo $stime;?>
    			<br />
    			<strong><a href="<?php the_permalink();?>"><?php the_title();?></a></strong>
    
    			<hr />
    
    	<?php endwhile; else: ?>
    	 <p><strong><?php include('inc/nope.php');?></strong></p>
    	<?php endif; ?>
    	<?php wp_reset_query(); ?>
  2. nadine00
    Member
    Posted 1 year ago #

    Updated, but its still just echoing January and not the right month, what am I missing? Anyone?

    <?php
        $args = array(
        'post_type' => 'events',
        'orderby' => 'meta_value',
        'meta_key' => 'tf_events_startdate',
        'order' => 'DESC'
        );
    
        $my_query = new WP_Query($args);
    
        if ($my_query->have_posts()) : while ($my_query->have_posts()) :
        $my_query->the_post();
    
        $custom = get_post_custom(get_the_ID());
    
        // dates
        $sd = $custom["tf_events_startdate"][0];
        $ed = $custom["tf_events_enddate"][0];
    
        // - local time format -
        $time_format = get_option('time_format');
        $stime = date($time_format, $sd);
        $etime = date($time_format, $ed);
    
        // set headers
    
        if(!isset($currentMonth) || $currentMonth != date("m", strtotime($sd))){
            $currentMonth = date("m", strtotime($sd));
    
         echo '<h2>'.date("F", strtotime($sd)).'</h2>';
    
        }?>
    
        <ul>
            <li>
            <strong><a href="<?php the_permalink();?>"><?php the_title();?></a></strong>
             <br />
            <?php // - determine if it's a new day -
            $longdate = date("l, M j, Y", $sd);
            if ($daycheck == null) { echo $longdate; }
            if ($daycheck != $longdate && $daycheck != null) { echo $longdate; } ?>
            <br />
            <?php echo $stime;?>
            <hr />
    
            </li>
        </ul>
        <?php endwhile; else: ?>
        <ul id="events">
        <li><?php _e('No Events Yet .'); ?></li>
        </ul>
        <?php endif; ?>
  3. frenchy black
    Member
    Posted 1 year ago #

    are you looking to do something similar to this webpage http://www.chestnutstreet4square.com/resources/ if so i can help

Topic Closed

This topic has been closed to new replies.

About this Topic