WordPress.org

Ready to get started?Download WordPress

Forums

Need a 2 column custom post type (3 posts)

  1. lee718
    Member
    Posted 2 years ago #

    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. ?>
  2. lee718
    Member
    Posted 2 years ago #

    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

  3. lee718
    Member
    Posted 2 years ago #

    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');

Topic Closed

This topic has been closed to new replies.

About this Topic