我正在尝试使用我的 Bootstrap .post-title 类做一些事情。
我想在我的帖子标题上放置一个 element.style 背景,作为背景,为每个帖子的帖子特色图像调用。我已经做到了这一点,但出了点问题,现在无法正常工作。我唯一知道的是一定看起来像这样。
<div class="post-featured" style="background-image:url('upload/<?php the_post_thumbnail( 'wpbs-featured' ); ?>')">
但是语法中有些地方是错误的,因为它在 HTML 上呈现这些字符。这是怎么回事?
')">
最佳答案
the_post_thumbnail
返回一个 IMG html 标签。所以生成的代码是
<div class="post-featured" style="background-image:url('upload/<img src="path/to/file.png">')">
绝对不是可行的东西......你只需要 url,所以你应该这样做:
$thumb_id = get_post_thumbnail_id();
$thumb_url = wp_get_attachment_image_src($thumb_id,'wpbs-featured', true);
<div class="post-featured" style="background-image:url('<?= $thumb_url[0] ?>')">
关于html - 这个语法有什么错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27768838/