如何在组合的PHP / HTML中显示缩略图和标题?

时间:2019-04-28 01:22:00

标签: php wordpress thumbnails

我想使用此代码片段显示帖子的标题和缩略图,但我无法这样做。

我该如何解决这个问题?

代码

<div class="row">
    <?php     
    if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'full');
        <div class="col-md-4">
            <div class="card" style="width: 18rem;">
                <img class="card-img-top" src="<?php the_post_thumbnail('thumbnail');?>    
    </div>    
    echo '<h5 class=" card-title "><a href=" '.get_permalink() .' ">'.get_the_title().'</a></h5 >';?>
    <p class="card-text "><?php echo get_the_excerpt(); ?></p> 
    <a href="<?php the_permalink();?>" class="btn btn-primary"> Continue Reading &raquo;
                </a>
            </div>
            <?php  
    endwhile;
    else :
        _e( 'Sorry, no posts matched your criteria.', 'textdomain' );
    endif;?>
    </div>

1 个答案:

答案 0 :(得分:1)

似乎您的HTML中可能包含PHP代码。也许尝试一下:

<div class="row">
    <?php 
        if ( have_posts() ) : while ( have_posts() ) : the_post(); $featured_img_url = get_the_post_thumbnail_url(get_the_ID(),'full'); ?> 
            <div class="col-md-4">
                <div class="card" style="width: 18rem;">
                    <img class="card-img-top" src="<?php the_post_thumbnail('thumbnail'); ?>
                </div>
                <?php  echo '<h5 class=" card-title "><a href=" ' . get_permalink() .' ">' . get_the_title() . '</a></h5 >'; ?>
                <p class="card-text"><?php echo get_the_excerpt(); ?></p> 
                <a href="<?php the_permalink(); ?>" class="btn btn-primary"> Continue Reading &raquo;</a>
            </div>
            <?php  endwhile;
            else :
                _e( 'Sorry, no posts matched your criteria.', 'textdomain' );
        endif; 
    ?>
</div>
  • 如果它不能解决您的问题,则可能要检查语法错误/警告。
  • 您可以考虑缩进代码,这将帮助您查找错误而无需查看错误日志。
相关问题