2016-12-12 67 views
0

新手在这里。我能够显示WordPress的特色图片URL,通过这个代码中使用它作为背景:如何正确显示WordPress的精选图片网址?

<header class="<?php x_masthead_class(); ?>" role="banner" <?php if (is_single()) : echo 'style="background-image: url(\''; echo the_post_thumbnail_url('full'); echo '\');"'; endif; ?> >

但是,当我试试这个方法:

<header class="<?php x_masthead_class(); ?>" role="banner" <?php if (is_single()) : echo 'style="background-image: url(\''; echo the_post_thumbnail_url('full'); echo '\');"'; endif; ?> >

我得到一个不同的结果,其中图像URL不显示正面t后background-image:url('。它显示在它之前,URL显示空格而不是/

我知道我可能会错过这件事。我试着用Google搜索,但我似乎无法找到解决方案。

在此先感谢您的帮助!

回答

0

功能the_post_thumbnail_url打印该URL,因此您不需要指令echo。所以我建议这条线代替:

<header class="<?php x_masthead_class(); ?>" role="banner"<?php if (is_single()) : ?> style="background-image: url('<?php the_post_thumbnail_url('full'); ?>');" <?php endif; ?> > 
相关问题