• I’d like to display on the index page the current month’s posts (an unknown number) divided into three columns. The middle column is wider than the other two and shows a medium-sized featured image rather than the thumbnail size. The middle column will also show a different type of excerpt. From different sources this is what I’ve pieced together so far:

    <?php
    /*
    Template Name: Three-column Index
    */
    get_header(); ?>
    
    <?php
    $current_month = date('m');
    $current_year = date('Y');
    $issue = array('year'=> $current_year,'monthnum'=> $current_month,'post_status'=>'publish','numberposts'=>-1);
    $numposts = count( get_posts( $issue ) );
    $columnOneTwoPosts = round($numposts / 3);
    if(3*$columnOneTwoPosts < $numposts) {
        $columnThreePosts = $columnOneTwoPosts + 1;
    } elseif(3*$columnOneTwoPosts > $numposts) {
        $columnThreePosts = $columnOneTwoPosts - 1;
    } elseif(3*$columnOneTwoPosts == $numposts) {
        $columnThreePosts = $columnOneTwoPosts;
    }
    $columnTwoOffset = $columnOneTwoPosts;
    $columnThreeOffset = 2*$columnOneTwoPosts;
    ?>
    
    <?php if (have_posts()) : ?>
    
        <h2><?php the_time('F Y'); ?></h2>
    
        <div class="row">
            <div class="col25">
    
            <?php query_posts('showposts='.$columnOneTwoPosts.'&offset=0'); ?>
            <?php while (have_posts()) : the_post(); ?>
    
                <article <?php post_class('module') ?>>
    
                    <div class="entry">
                        <figure>
                            <a href="<?php the_permalink() ?>" class="block-link"></a>
                            <?php if ( has_post_thumbnail()) : ?>
                            <?php the_post_thumbnail('thumbnail', array ('class' => 'featured-image')); ?>
                            <?php endif; ?>
                            <figcaption><?php the_category(', ') ?></figcaption>
                         </figure>
                         <h2 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
                         <?php echo custom_field_excerpt(); ?>
                         <a href="<?php the_permalink() ?>" class="button"><span>Read More</span></a>
                    </div>
    
                 </article>
    
                 <?php endwhile; ?>
    
             </div><!-- .col25 -->
             <div class="col45">
    
                 <?php query_posts('showposts='.$columnOneTwoPosts.'&offset='.$columnTwoOffset); ?>
                 <?php while (have_posts()) : the_post(); ?>
    
                 <article <?php post_class('module') ?>>
    
                    <div class="entry">
                        <figure>
                            <a href="<?php the_permalink() ?>" class="block-link"></a>
                            <?php if ( has_post_thumbnail()) : ?>
                            <?php the_post_thumbnail('medium', array ('class' => 'featured-image')); ?>
                            <?php endif; ?>
                            <figcaption><?php the_category(', ') ?></figcaption>
                         </figure>
                         <h2 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
                         <p><?php the_field('short_excerpt'); ?></p>
                         <a href="<?php the_permalink() ?>" class="button"><span>Read More</span></a>
                    </div>
    
                 </article>
    
                 <?php endwhile; ?>
    
             </div><!-- .col45 -->
             <div class="col25">
    
                 <?php query_posts('showposts='.$columnThreePosts.'&offset='.$columnThreeOffset); ?>
                 <?php while (have_posts()) : the_post(); ?>
    
                 <article <?php post_class('module') ?>>
    
                    <div class="entry">
                        <figure>
                            <a href="<?php the_permalink() ?>" class="block-link"></a>
                            <?php if ( has_post_thumbnail()) : ?>
                            <?php the_post_thumbnail('thumbnail', array ('class' => 'featured-image')); ?>
                            <?php endif; ?>
                            <figcaption><?php the_category(', ') ?></figcaption>
                        </figure>
                        <h2 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
                        <?php echo custom_field_excerpt(); ?>
                        <a href="<?php the_permalink() ?>" class="button"><span>Read More</span></a>
                    </div>
    
                 </article>
    
                 <?php endwhile; ?>
    
             </div><!-- .col25 -->
        </div><!-- .row -->
    
        <?php if (show_pagination()) : ?>
    
            <div class="navigation">
    
                    <?php previous_posts_link('< Prev', '0'); ?>
    
                    <?php
                    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                    echo '&nbsp;Page ' . $paged . ' of ' . $wp_query->max_num_pages . '&nbsp;';
                    ?>
    
                    <?php next_posts_link('Next >', '0'); ?>
    
            </div><!-- .navigation -->
    
        <?php endif; ?>
    
    <?php else : ?>
    
        <h2><?php _e('Nothing Found','theme'); ?></h2>
    
    <?php endif; ?>
    
    <?php get_sidebar(); ?>
    
    <?php get_footer(); ?>

    It is showing however all posts and not just ones from the current month besides showing repeat posts per column. The navigation is also broken.

  • The topic ‘Index with multiple loops of current month's content in 3 columns’ is closed to new replies.