如何在帖子标题上方添加Wordpress图像缩略图

时间:2018-04-03 20:43:26

标签: php wordpress

尝试编辑主题内的帖子页面,并希望在帖子标题上方添加缩略图,但它会将缩略图放在帖子标题的末尾。任何帮助表示赞赏。

    if (have_posts()) :
                echo "<h1>" . __('Valhalla Integration Blog','avia_framework') . "</h1>";
                echo "<ul>";
                    while (have_posts()) : the_post(); 

                if ( has_post_thumbnail() ) {
                    the_post_thumbnail();
                }

                    echo "<li><h4><a href='".get_permalink()."' rel='bookmark' title='". __('Permanent Link:','avia_framework')." ".the_title_attribute('echo=0')."'>".get_the_title()."</a></h4></li>";

                    endwhile;
                echo "</ul>";
                else:

                  echo "<h3>" . __('No Blog Posts found','avia_framework') . "</h3>";

                endif;

1 个答案:

答案 0 :(得分:2)

您将<img>标记回显到<ul>,这是无效的HTML。我对其进行了修改,以回显<li>内的图像,该图像也包含您的标题。

if (have_posts()) :
echo "<h1>" . __('Valhalla Integration Blog','avia_framework') . "</h1>";
echo "<ul>";
    while (have_posts()) : the_post(); 

    echo "<li>";

        if ( has_post_thumbnail() ) {
        the_post_thumbnail();
    }

    echo "<h4><a href='".get_permalink()."' rel='bookmark' title='". __('Permanent Link:','avia_framework')." ".the_title_attribute('echo=0')."'>".get_the_title()."</a></h4></li>";

    endwhile;
echo "</ul>";
else:

echo "<h3>" . __('No Blog Posts found','avia_framework') . "</h3>";

endif;