• I am using twentyeleven theme (AND A CHILD THEME) and have my custom post types set up. I’d like to have two columns of blog posts (not a sidebar).

    I found this code on digital raindrops that I’d like to incorporate into the page but I don’t know how. I tried it a few different ways and it came out botched. Would really appreciate your help.

    <?php /* Start Two Column Support */ ?>
    <?php $counter = 1; ?>
    
    <?php /* Start the Loop */ ?>
    <?php while ( have_posts() ) : the_post(); ?>
    
    <?php /* Two Column Support get class */ ?>
    <?php $class = ( $counter % 2  ? ' one' : '' ) ?>
    <?php $first = ( $counter < 3  ? ' first' : '' ) ?> 
    
    <?php /* Two Column output open the div class */ ?>
    <div class="column<?php echo $class; echo $first; ?>">
    
    <?php get_template_part( 'content', 'index' ); ?>
    
    <?php /* End Two Column Support close div class */ ?></div>
    <?php $counter++; //Update Counter ?>

    and the custom post type code is:

    <?php while ( have_posts() ) : the_post();
    $args = array( 'post_type' => 'custom-a', 'posts_per_page' => 6 );
    $loop = new WP_Query( $args );	
    
    while ( $loop->have_posts() ) : $loop->the_post();
    the_title('<h2 class="custom-a-title">','</h2>');
    echo '<div class="custom-a-post">';	
    
    the_excerpt();	
    
    echo '</div>';
    endwhile; // end of the loop. ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter lee718

    (@lee718)

    by the way, if anyone knows another way to do 2 column with css, I’d be interested in knowing. I tried it this way too but it just went one column to the left without the right column.
    Thanks

    Thread Starter lee718

    (@lee718)

    I’ve since tried to place the two-columns using shortcodes. Right now the posts are in half columns but stacking on left instead of left/right, so in one column but 50% of page basically. Can anyone help me with this? I would really appreciate it. Here’s the code in my custom post in template child page:

    <?php while ( have_posts() ) : the_post();
    $args = array( 'post_type' => 'dozen_runners', 'posts_per_page' => 2 );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();
    the_title('<h2 class="post-title">','</h2>');
    echo '<div class="one_half">';
    the_post_thumbnail('thumbnail', array('class' => 'alignleft'));
    		    echo do_shortcode(wpautop(wptexturize(get_the_excerpt())));
    echo '</div>';
    endwhile; // end of the loop. ?>

    and in functions.php:

    function webtreats_one_third( $atts, $content = null ) {
    return '<div class="one_third">' . do_shortcode($content) . '</div>';
    }
    function webtreats_one_half( $atts, $content = null ) {
    		   return '<div class="one_half">' . do_shortcode($content) . '</div>';
    		}
    add_shortcode('one_half', 'webtreats_one_half');
    
    function webtreats_one_half_last( $atts, $content = null ) {
    return '<div class="one_half last">' . do_shortcode($content) . '</div><div class="clearboth"></div>';
    }
    add_shortcode('one_half_last', 'webtreats_one_half_last');
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Need a 2 column custom post type’ is closed to new replies.