我试图在 wordpress 中获取帖子的特色图片并将其输出为 div 的背景图片并将其与 div 的右下角对齐。
到目前为止,我的代码如下所示,但是 background-image: url(' . wp_get_attachment_url() . ');
返回为 background-image: url();
代码执行时。
提前感谢任何可以提供帮助的人!
<?php
query_posts(array( 'category_name' => 'what-we-do'));
if(have_posts()) : while(have_posts()) : the_post();
?>
<div>
<?php
echo do_shortcode( '
[expand title="' . get_the_title() . '" swaptitle="Close" trigpos="below" id="' . get_the_ID() . '" trigclass="arrowright" rel="whatwedo-highlander"]
<h4 class="collapse-inner-title">' . get_the_title() . '</h4>
<div class="whatwedo-collapse-background-img" style="background-image: url(' . wp_get_attachment_url() . '); background-position: right bottom;">
<div class="whatwedo-collapse-content">' . get_the_content() . '</div>
</div>
[/expand]
' );
?>
</div>
<?php
endwhile;
endif;
wp_reset_query();
?>
最佳答案
试试这个:
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
然后我们在$image[0]
的时候设置background-image
关于php - Wordpress - 在 PHP 的短代码中使用特色图像作为 div 背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26036921/