php - 如何在组合的 PHP/HTML 中显示缩略图和标题?
问题描述
我想使用此代码段显示我的帖子的标题和缩略图,但我无法这样做。
我该如何解决这个问题?
代码
<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 »
</a>
</div>
<?php
endwhile;
else :
_e( 'Sorry, no posts matched your criteria.', 'textdomain' );
endif;?>
</div>
解决方案
看来您的 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 »</a>
</div>
<?php endwhile;
else :
_e( 'Sorry, no posts matched your criteria.', 'textdomain' );
endif;
?>
</div>
- 如果它没有解决您的问题,请查看您的语法错误/警告。
- 您可能会考虑缩进您的代码,它可以帮助您在不查看错误日志的情况下找到错误。
推荐阅读
- typescript - Vue.extend() + TypeScript = 方法必须指定事件:MouseEvent,我该如何避免呢?
- python - 在用 GD 拟合我自己的回归时,内核似乎已经死了
- pine-script - 在分钟图表上突出显示每个半小时条的最后一个
- python - 如何从 Python 中的 H2O GBM 模型对象中检索标题名称?
- php - 输入命令时出错 => php artition route:list
- python - Python长格式:减去行的选择
- angular - 如何重置ngrx 9的整个商店?
- sql-server - 为什么在 SQL Server 中乘 DECIMAL 时会出现精度损失?
- python - Matplotlib 绘图的透明背景
- linux-kernel - 如何使用 eBPF 修改用户空间内存?