WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] displaying last 3 post on home page in a 3 colume layout (5 posts)

  1. kitcorsa
    Member
    Posted 1 year ago #

    im trying to get my last 3 post to display on my homepage as a 3 colum layout. The layout is divs and css and works fine but on the last colum it needs a class of "last"

    i cant for the love of me get the last one to display as last, here is where i got to.

    <?php for ($i = 1; $i <= 3; $i++) { ?>
    <?php
    $args = array( 'numberposts' => 3 );
    $lastposts = get_posts( $args );
    foreach($lastposts as $post) : setup_postdata($post); ?>
    <div class="boxes one_third <?php if ($i == 3) {echo "last";} ?>">
    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    <?php the_content(); ?>
    </div>
    <?php endforeach; ?>
    <?php } ?>

    but this displays 3 post 3 time, so shows 9 post in all repeating

  2. Andrew
    Forum Moderator
    Posted 1 year ago #

    Can you not use CSS last-child instead?
    http://www.w3schools.com/cssref/sel_last-child.asp

  3. kitcorsa
    Member
    Posted 1 year ago #

    not if people are usin less than ie8

  4. Andrew
    Forum Moderator
    Posted 1 year ago #

    What about jQuery's equivalent?

  5. kitcorsa
    Member
    Posted 1 year ago #

    does work that way though

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.