WordPress.org

Ready to get started?Download WordPress

Forums

Only display featured image of the first post (2 posts)

  1. hungken
    Member
    Posted 11 months ago #

    I want to know how to displayed random post like image below:

    http://i.imgur.com/ejNRh1e.png

    That is, the code will display a list of 8 random posts, but only show the first post featured image and post excerpts of it. the next post will show the title and nothing else

    Please give me the code to do this! I use it to insert a widget supports PHP, If possible, please include simple css

    Thanks for your help!!!!

    (Sorry for my english)

  2. samcrawshaw
    Member
    Posted 11 months ago #

    Something like this?

    <?php
    $recent = new WP_Query("showposts=7");
    while($recent->have_posts()) : $recent->the_post();
    $counter++;?>
    <ul>
    <?php if($counter == 1){
    the_post_thumbnail();}?>
    <li><h3><?php the_title(); ?></h3></li>
    <li><?php the_excerpt();?></li>
    <?php if($counter > 1){?>
    <li><h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3></li>
    }?>
    <?php endwhile; ?>
    </ul>

    Can't check it at the moment, might have errors.

    Sorry, your on your own with the CSS.

Reply

You must log in to post.

About this Topic

Tags

No tags yet.