featured image background

时间:2019-08-20 作者:user3547342

正在尝试在Functions中创建短代码。php显示特色帖子。。

我所拥有的一切都很好,只是我无法获得背景图像来显示帖子的特色图像。。。

echo$featured\\u post\\u url显示正确的地址,但我无法将其显示为div的背景图像。。。

也许我盯着电脑屏幕看得太久了。。。有人能告诉我我在这里错过了什么吗?

    function propertunity_featured_post() {
      $featured_post_id = 2860;
      $featured_post = get_post($featured_post_id);
      $featured_post_url = get_permalink($featured_post_id);

      $featured_post_image_url = wp_get_attachment_url( 
      get_post_thumbnail_id($featured_post_id, \'thumbnail\') );

      echo "

        <div class=\'card\'>

          <div class=\'card-header\' style=\'background-color: #f8f8fc; overflow: hidden;\'>

            <a href=\'" . $featured_post_url . "\'>

              <div class=\'card__image\' style=\'background-image: url(\' " . $featured_post_image_url . " \');\'></div>       

            </a>

          </div>

       </div>";

1 个回复
SO网友:Tanmay Patel

你可以试试wp_get_attachment_image_src 这是用于获取功能图像URL的。这是完整的代码。

<?php
function propertunity_featured_post() {
      $featured_post_id = 2860;
      $featured_post = get_post($featured_post_id);
      $featured_post_url = get_permalink($featured_post_id);
      $featured_post_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($featured_post_id, \'thumbnail\') );
      echo "<div class=\'card\'>
          <div class=\'card-header\' style=\'background-color: #f8f8fc; overflow: hidden;\'>
            <a href=\'" . $featured_post_url . "\'>
              <div class=\'card__image\' style=\'background-image: url(\' " . $featured_post_image_url[0] . " \');\'></div>       
            </a>
          </div>
       </div>";
}
?>

相关推荐