Here is my WordPress template file. It takes 6 recent posts and displays these 6 posts in two columns per rpw. the columns divs are variables: $hol=1 and $hol=2.
Here is the code of my template file:
<div id="page-full-width"><?php query_posts('showposts=6'); ?>
<?php $hol = 1; ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php if (in_category('3')) continue; ?>
<?php if (in_category('4')) continue; ?>
<?php if ($hol == 1) echo "<div class=\"main-content\">"; ?>
<div class="large-6 columns post hol<?php echo $hol;?>" id="post-<?php the_ID(); ?>">
<?php if ( get_post_meta($post->ID, 'thumb', true) ) { ?>
<?php } else { ?>
<?php } ?>
<h2><a title="Permanent Link to <?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<p><?php the_excerpt(); ?><br></p>
<?php if ($hol == 2) echo "</div>";
(($hol==1) ? $hol=2 : $hol=1); ?>
</div><!--/post-->
<?php endwhile; ?>
<?php endif; ?>
I've tried several solutions, like changing the lines to
<?php if ($hol == 3) echo "</div>";
(($hol==1) ? $hol=3 : $hol=2 : $hol=1); ?>
but it always resulted in a white screen. My questions are: Is it possible to modify the query and display the content in 3 columns instead of 2 columns (of course, each div would be "large-4 columns" then) ?
Could I query posts only from custom post type, i.e. jobs ?
Thank you.
Following renders the 3 column structure instead of two. Div with id "page-full-width" is not closed in this code. Hope you know where it is closed.
<div id="page-full-width">
<?php query_posts('post_type'=> 'jobs', 'showposts=6'); ?>
<?php $hol = 1; ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php if (in_category('3')) continue; ?>
<?php if (in_category('4')) continue; ?>
<div class="main-content">
<?php for($hol;$hol<=3;$hol++){ ?>
<div class="large-4 columns post hol<?php echo $hol;?>" id="post-<?php the_ID(); ?>">
<?php if ( get_post_meta($post->ID, 'thumb', true) ) { ?>
<?php } else { ?>
<?php } ?>
<h2><a title="Permanent Link to <?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<p><?php the_excerpt(); ?><br></p>
</div>
<?php } ?>
</div><!--end .main-content-->
<?php endwhile; ?>
<?php endif; ?>
For querying posts only from custom post type "jobs", you can update the "query_posts" as follows:
query_posts( array( 'post_type'=>'jobs', 'posts_per_page'=>6 ) );
Hope this helps.