• Resolved alianna

    (@alianna)


    I want to display my home (root) page a little differently from most blogs, but I’m not sure how to go about coding the loop for this.

    The first entry on the page displays normally, in its entirety. Under that, side by side, the next two entries (excerpts) are displayed in side-by-side divs, #col-1 and #col2.

    I found how to display the first entry differently than the rest of the loop, but I’m not sure how to place subsequent entries of the loop into different titled divs.

    Any help is greatly appreciated!

Viewing 4 replies - 1 through 4 (of 4 total)
  • One way to accomplish this is to generate the div(s) for all three posts this way (inside and at the start of The Loop):

    <?php
    $postcount++;
    switch( $postcount ) {
    case 1:
        $div_id = 'main';
        break;
    case 2:
        $div_id = 'col-1';
        break;
    case 3:
        $div_id = 'col-2';
        break;
    }
    ?>
    <div id="<?php echo $div_id; ?>">

    Thread Starter alianna

    (@alianna)

    Is there anything else I need to put within the loop to make this work?

    And is there a way that I can have case four and on be normal, so that I can have pagination within index.php?

    Thank you for the help so far ??

    Is there anything else I need to put within the loop to make this work?

    Not unless there are additional divs in use to wrap your columns and such. Otherwise it should work as is.

    And is there a way that I can have case four and on be normal, so that I can have pagination within index.php

    Define “normal.” If you mean to say that posts on paginated pages will not be laid out in columnar fashion, you can do this:

    <?php
    $postcount++;
    if( is_home() && !is_paged() ) {
    	switch( $postcount ) {
    	case 1:
    	    $div_id = 'main';
    	    break;
    	case 2:
    	    $div_id = 'col-1';
    	    break;
    	case 3:
    	    $div_id = 'col-2';
    	    break;
    	}
    } else {
    	$div_id = 'content'; // default id value
    }
    ?>
    <div id="<?php echo $div_id; ?>">

    Thread Starter alianna

    (@alianna)

    Thank you! That’s exactly what I was looking for. I’ll let you know if I can’t get it to work.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Multiple loops? Or easier way?’ is closed to new replies.