【问题标题】:Separating title from thumbnail on wordpress在wordpress上将标题与缩略图分开
【发布时间】:2015-02-14 05:29:09
【问题描述】:

我正在做一个 wordpress 主题,我正在尝试在我的侧边栏上最近发布的帖子的缩略图和帖子标题之间创建一些边距。我尝试了一切,但它不起作用。有什么建议吗?

<?php $recent_posts = wp_get_recent_posts();
foreach( $recent_posts as $recent ){
if($recent['post_status']=="publish"){
if ( has_post_thumbnail($recent["ID"])) {
    echo '<li style=" list-style: none; ">
    <a class="post-title" href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' .   get_the_post_thumbnail($recent["ID"], 'thumbnail').$recent["post_title"].'</a></li> ';
}else{
    echo '<li style=" list-style: none; ">
    <a class="post-title" href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' .   $recent["post_title"].'</a></li> ';
}
 }
}
?> 

【问题讨论】:

    标签: php css wordpress themes sidebar


    【解决方案1】:

    您是否尝试在它们之间插入换行符?

    get_the_post_thumbnail($recent["ID"], 'thumbnail') . '<br />' . $recent["post_title"].'
    

    或

    将此添加到 CSS 文件中:

    img.attachment-thumbnail { margin:10px; }
    

    【讨论】:

    • 嘿,谢谢你的帮助。是的,CSS 工作!现在,问题是标题在底部而不是顶部。它看起来像这样:i.imgur.com/WggSQWQ.png 我希望它看起来像这样:i.imgur.com/oAaSLpt.png 我无法将文本放置在正确的位置,我认为这是由于我之前发布的代码。
    • 我认为,最简单的方法是在标题后添加一个或多个换行符,因此:$recent["post_title"].'&lt;br /&gt;'. OR $recent["post_title"].'&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;'.
    • 不幸的是,它没有用。 tbh,没有任何改变:/ 对于 3
      ,唯一改变的是“行”之间的空间
    猜你喜欢
    • 2014-09-28
    • 2015-11-20
    • 1970-01-01
    • 2012-09-15
    • 2011-08-09
    • 2011-09-04
    • 2011-02-08
    • 2015-07-19
    • 1970-01-01
    相关资源
    最近更新 更多