Getting last 5 post titles from WordPress and it’s thumbnail

I’m creating news slider and it looks like this

< ___________ #slideContent _______________>  <#slideMenu>
┌────────────────────────────────────────────┬────────────┐
│                                            │<1st title> │
│                                            ├────────────┤
│       (Thumbnail of hovered title (1st))   │ 2nd title  │
│                                            ├────────────┤
│                 (___/)                    │ 3rd title  │
│                 (=’.'=)                    ├────────────┤
│                 (")_(")                    │ 4th title  │
│                                            ├────────────┤
│                                            │ 5th title  │
└────────────────────────────────────────────┴────────────┘
< > means hovered 
Bunny is that article's thumbnail of hovered title. :)

And here is my code of it.

Read More
<div id="slideshow">
 <div id="slideContent">
    <?php ???GET THUMBNAIL OF HOVERED TITLE?? ?>
 </div>
 <div id="slideMenu">
         <div id="slideM1" class="marBo20"><?php ??GET TITLE OF LAST POST??></div>
         <div id="slideM2" class="marBo20"><?php ??GET TITLE OF 2ND LAST POST??></div>
         <div id="slideM3" class="marBo20"><?php ??GET TITLE OF 3RD LAST POST??></div>
         <div id="slideM4" class="marBo20"><?php ??GET TITLE OF 4TH LAST POST??></div>
         <div id="slideM5"><?php ??GET TITLE OF 5TH LAST POST??></div>
 </div>
</div>

I don’t know what to type into the #slideM1, #slideM2, #slideM3, #slideM4, #slideM5 DIVs and what to place inside a slideContent.

Thank you for any help. 🙂

Related posts

Leave a Reply

1 comment

  1. You may need to modify this for your DIVs but here is your solution in a <ul> list (From WordPress Codex):

    <ul>
    <?php
    
    global $post;
    
    $args = array(
        'numberposts' => 5,
        'orderby' => 'post_date',
        'order' => 'DESC',
        'post_type' => 'post',
        'post_status' => 'publish'
    );
    
    $myposts = get_posts( $args );
    
    foreach( $myposts as $post ) : setup_postdata($post); ?>
        <li>
            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
        </li>
    <?php endforeach; ?>
    </ul>
    

    Here is a DIV version from your example I’ve just made. The only thing missing is the post thumbnails:

     <div id="slideshow">
     <div id="slideContent">
    
     </div>
     <div id="slideMenu">
        <?php
    
        global $post;
    
        $args = array(
            'numberposts' => 5,
            'orderby' => 'post_date',
            'order' => 'DESC',
            'post_type' => 'post',
            'post_status' => 'publish'
        );
    
        $myposts = get_posts( $args );
                $count = 0;
    
        foreach( $myposts as $post )
        {
            $count++;
            setup_postdata($post);
        ?>
            <div id="slideM<?php echo $count; ?>" class="marBo20"><a href="<?php echo the_permalink(); ?>"><?php the_title(); ?></a></div>
        <?php } ?>
    </div>
    </div>