user2013488
user2013488

Reputation: 363

wordpress image isn't displaying where it supposed to

I'm trying to create a small wp plugin for my blog, but I've got the following problem.

The post image, isn't displaying in the right spot.

This is the proper HTML

<li>

    <div class="projects">

        <ul class="projects sticker">
        <li><h2><?php the_title(); ?></h2></li>
        <li><p><a href="">details</a></p></li>
        </ul>
        <img src="" />

    </div>

    </li>

This is how it's displaying now

      <li>

    <div class="projects">

        <ul class="projects sticker">
        <li><h2><?php the_title(); ?></h2></li>
        <li><p><a href="">details</a></p></li>
        </ul>


    </div>

    </li> 
    <img src="" /> 

Basically i have to put the img tag inside the list and div

Here is my code so far

        $args = array( 'numberposts' => '3','category' => $cat_id );
        $recent_posts = wp_get_recent_posts( $args );
        foreach( $recent_posts as $recent ){
         echo '<li>'
     . '<div class="projects">'
     . '<ul class="projects sticker">'
     . '<li>'
     . '<h2>'
     . '<a href="' . get_permalink($recent["ID"]) . '" title="Look   '.esc_attr($recent["post_title"]).'" >'
     . $recent["post_title"]
     . '</a>'
     . '</h2>'
     . '</li>'
     . '<li><p><a href="">details</a></p></li>'
     . '</ul>'
     . '<img src="'.the_post_thumbnail('thumbnail').'" />'
     . '</div>'
     . '</a>'; 

Upvotes: 0

Views: 115

Answers (2)

Giacomo1968
Giacomo1968

Reputation: 26066

You have an extra closing <li> at the end and the placement of the closing tag of the first <li> is improperly nested and <a href> opening & closing tag is misplaced as well. Also you could have solved this problem easier—possibly by yourself—if you format the code so humans it can more easily be read. Piling on a stack of instructions on one line like that will only cause confusion:

        $args = array( 'numberposts' => '3','category' => $cat_id );
        $recent_posts = wp_get_recent_posts( $args );
        foreach( $recent_posts as $recent ){
         echo '<li>'
         . '<div class="projects">'
         . '<ul class="projects sticker">'
         . '<li>'
         . '<h2>'
         . '<a href="' . get_permalink($recent["ID"]) . '" title="Look   '.esc_attr($recent["post_title"]).'" >'
         . $recent["post_title"]
         . '</a>'
         . '</h2>'
         . '</li>'
         . '<li><p><a href="">details</a></p></li>'
         . '</ul>'
         . '<img src="'.the_post_thumbnail('thumbnail').'" />'
         . '</div>'
         . '</a>'
         ; 

Upvotes: 1

Yogesh Suthar
Yogesh Suthar

Reputation: 30488

use this code, you have used extra <li></li>

$args = array( 'numberposts' => '3','category' => $cat_id );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
     echo '<a href="' . get_permalink($recent["ID"]) . 
          '" title="Look   '.esc_attr($recent["post_title"]).'" >'  
          .'<div class="projects">' .'<ul class="projects sticker">'       
          .'<li>' .'<h2>' .   $recent["post_title"] .'</h2>' .'</li>' 
          .'<li><p><a href="">details</a></p></li></ul>' 
          .'<img src="'.the_post_thumbnail('thumbnail').'" />'  
          .'</div>' .'</a>'; 
}

Upvotes: 2

Related Questions