0

I'm building a website (with Wordpress 3.6) and would like to put the news/articles arranged as follows:

  • The first article was with the maximum size (one column);

  • The following articles were arranged in two columns.

Appears only 5 or 7 articles per page. How to do this?

1 Answer 1

2

Test and let me know:

Put the following code into your index.php (or front-page.php):

<?php if( have_posts() ) : ?>

        <div class="col-full">
            <?php for( $news = 0; $news < 1; $news++ ) { ?>
                <?php the_post(); ?>
                <h3 class="news-title"><?php the_title(); ?></h3>
                <div class="news-excerpt"><?php the_excerpt(); ?></div>
            <?php } ?>
        </div>
        <div class="place-for-ad"></div>

        <?php // Start Two Column Support ?> 
        <?php $col_counter = 1; ?>

        <?php // Controll the loop's max number (4 here) to echo the max number of news with 2 column ?>
        <?php for( $news = 0; $news < 4; $news++ ) { ?>

            <?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="col-2<?php echo $class; echo $first; ?>">
                <?php the_post(); ?>
                <h3 class="news-title"><?php the_title(); ?></h3>
                <div class="news-excerpt"><?php the_excerpt(); ?></div>
            </div> <!-- End Two Column Support close div class -->

        <?php $col_counter++; //Update Counter ?>

        <?php } ?>

<?php endif; ?>

And put the following to your Stylesheet (style.css):

.col-full{
    width: 100%;
    float: left;
    position: relative;
    }

.clear{
    clear: both;
    }

/* Common for all the column */
.col-2{
    float: left;
    position: relative; 
    width: 47%; 
    border-top: dashed 1px #ccc; 
    }

/* Loads only on first columns */
.one { 
   clear: both; 
   margin-right: 2%; 
    } 

/* Loads on only the first 3 columns to make the top border into none */
.first {
    border-top: none;
    }
3
  • Hi Again! I changed a little the page (sdrv.ms/16z5P8v). Is there any way to change this so that spaces are added automatically and not appear empty spaces when there are no articles? Commented Sep 22, 2013 at 14:15
  • View it: sdrv.ms/19u4zEk Commented Sep 22, 2013 at 14:20
  • You are right, it produces some blank div even with no post. Try something as Caroline suggested here, with a while loop with inner $counter. Commented Sep 22, 2013 at 17:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.