• i got this code but doesnt work normaly: both columns arent equal(same number of posts on each one), how can i have two columns with equal posts on each one? thanks for your help

    <?php get_header(); ?>
    
    	<div id="content" class="narrowcolumn">
    <div class="column-left">
    	<?php if (have_posts()) : ?>
    
    		<?php while (have_posts()) : the_post(); ?>
    		<?php $post_counter++; if($post_counter > 4) : ?>
    
    </div>
    
    <div class="column-right">
    <?php endif; ?>
    
    <div class="post" id="post-<?php the_ID(); ?>">
    				<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Lien vers <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    				<small><?php the_time('j F Y') ?> | <?php comments_popup_link('Aucun commentaire', '1 Commentaire', '% Commentaires'); ?> | <?php the_category(', ') ?> </small>
    
    				<div class="entry">
    				<?php ob_start(NULL);
    						the_excerpt();
    
    					$tmp = ob_get_contents();
    					ob_clean();
    					the_permalink();
    					$permalink = ob_get_contents();
    					ob_clean();
    					the_title_attribute();
    					$title = ob_get_contents();
    					ob_end_clean();
    					$link = '<a href="'.$permalink.'" rel="bookmark" title="Lien vers '.$title.'">[...]</a>';
    					$tmp = str_replace('[...]',$link,$tmp);
    					//the_excerpt doesn't show [...] for user defined excerpts. in such cases always put our read more link
    					if(!empty($post->post_excerpt)) {
    					     //This post have an excerpt, let's display it
    						 $link = $link.'</p>';
    					     $tmp = str_replace('</p>',$link,$tmp);
    					}
    					echo $tmp;
    					?>
    				</div>
    
    			</div>
    
    		<?php endwhile; ?>
    		</div>
    
    		<div class="navigation">
    			<div class="alignleft"><?php next_posts_link('&laquo; Articles précédents') ?></div>
    			<div class="alignright"><?php previous_posts_link('Articles suivants &raquo;') ?></div>
    		</div>
    
    	<?php else : ?>
    
    		<h2 class="center">Page non trouvée!</h2>
    		<p class="center">L'article que vous cherchez n'existe pas. Il a pu être supprimé ou renommé. Veuillez utiliser les menus de navigation ou la barre de recherche pour le retrouver.</p>
    
    	<?php endif; ?>
    
    	</div>
    
    <?php get_sidebar(); ?>
    
    <?php get_footer(); ?>

Viewing 5 replies - 1 through 5 (of 5 total)
  • I’d suggest having one loop and use CSS to display the double columns.

    Don’t call your column “column-left”, just “column”

    Define its css to include

    float: left;
    width: 49%;

    That will automatically create two columns – the first post to the left, the second to the right, the third to the left, the 4th to the right, etc
    As the float will cause them to line up next to each other. with total width of 98% (49% times 2) two posts will “fit” on one line, then the 3rd will drop to the next line. You can put borders on the Div if needed to create a separation between the columns

    Thread Starter daft02

    (@daft02)

    thank you, how can i configure one loop?
    (btw anyone sees the point in using this ob_start php function? i didnt code this php index myself..just trying to make it work properly)

    if you use one loop you don’t need the buffering from ob_start

    I’m not guaranteeing this code is 100% correct. I just stripped out what I think you don’t need.

    actually its not #column that needs the CSS changes but .post Both columns will be contained within div id=”column”
    .post { float: left; width: 49%; }

    <?php get_header(); ?>
    
    	<div id="content" class="narrowcolumn">
    <div class="column">
    	<?php if (have_posts()) : ?>
    		<?php while (have_posts()) : the_post(); ?>
    
    <div class="post" id="post-<?php the_ID(); ?>">
    				<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Lien vers <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    				<small><?php the_time('j F Y') ?> | <?php comments_popup_link('Aucun commentaire', '1 Commentaire', '% Commentaires'); ?> | <?php the_category(', ') ?> </small>
    
    				<div class="entry">
    				the_excerpt();
    				the_permalink();
    				the_title_attribute();
    				$link = '<a href="'.$permalink.'" rel="bookmark" title="Lien vers '.$title.'">[...]</a>';
    					$tmp = str_replace('[...]',$link,$tmp);
    					//the_excerpt doesn't show [...] for user defined excerpts. in such cases always put our read more link
    					if(!empty($post->post_excerpt)) {
    					     //This post have an excerpt, let's display it
    						 $link = $link.'</p>';
    					     $tmp = str_replace('</p>',$link,$tmp);
    					}
    					echo $tmp;
    					?>
    				</div>
    
    			</div>
    
    		<?php endwhile; ?>
    		</div>
    
    		<div class="navigation">
    			<div class="alignleft"><?php next_posts_link('&laquo; Articles précédents') ?></div>
    			<div class="alignright"><?php previous_posts_link('Articles suivants &raquo;') ?></div>
    		</div>
    
    	<?php else : ?>
    
    		<h2 class="center">Page non trouvée!</h2>
    		<p class="center">L'article que vous cherchez n'existe pas. Il a pu être supprimé ou renommé. Veuillez utiliser les menus de navigation ou la barre de recherche pour le retrouver.</p>
    
    	<?php endif; ?>
    
    	</div>
    
    <?php get_sidebar(); ?>
    
    <?php get_footer(); ?>
    Thread Starter daft02

    (@daft02)

    yes i floated the post and didnt add any additional markup to the wp default theme.
    thanks

    Thread Starter daft02

    (@daft02)

    .widecolumn .post let you set the post width in its single page so no need of % parameters

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘how to make this code a true double column index.php’ is closed to new replies.