2013-02-13 70 views
0

我正在尝试为我的博客创建一个小的wp插件,但我遇到了以下问题。wordpress图像不显示它应该在哪里

帖子图片未显示在正确的位置。

这是正确的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> 

这是它是如何显示现在

 <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="" /> 

基本上我已经把名单和DIV中的img标签

这里是我的代码到目前为止

 $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>'; 

回答

1

您已经在最后一个额外的收盘<li>和第一<li>的结束标记的位置不正确嵌套和<a href>开&关闭标签放错了地方,以及。你也可以更容易地解决这个问题 - 可能由你自己 - 如果你格式化代码,使人类更容易阅读。在这样的一条线上堆叠指令堆只会造成混淆:

 $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>' 
     ; 
+0

之外谢谢。现在它在列表中,但在div之外。我在html中查找了其他语法错误,但我没有找到任何。 – user2013488 2013-02-13 11:12:43

+0

对不起,但没有你的其他代码,我不太清楚你期望任何人做什么来帮助。我最好的建议是简单地清理你的代码。我敢打赌,问题会解决,因为它是如此混乱。 – JakeGould 2013-02-13 11:22:49

+0

傻了,我发现我的错误。是的,我的代码是一团糟,因为我已经有了这个习惯来清理我的代码,当它已经完成。这是我会尝试解决的。再次感谢你。 – user2013488 2013-02-13 11:29:33

2

使用此代码,您使用额外<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>'; 
} 
+0

不行,不是这样。问题仍然存在 – user2013488 2013-02-13 10:48:52

+0

@ user2013488种子编辑答案,你在关闭'li'后关闭'h2' – 2013-02-13 10:51:58

+0

这里的结果相同。 img在列表中,但在div – user2013488 2013-02-13 11:16:10