【发布时间】:2014-11-16 04:02:31
【问题描述】:
我正在尝试弄清楚如何将精选帖子图片作为背景(在 Wordpress 上),但无法使其正常工作。 请参阅下面我正在使用的代码。 $thumbimg 应该拉出特色图片,但显然我在那里做错了。
$lessons = get_posts( $args );
if( count( $lessons ) > 0 ) {
$html .= '<section class="module-lessons">';
$html .= '<header><h3>' . __( 'Lessons', 'sensei_modules' ) . '</h3></header>';
$thumbimg = wp_get_attachment_image_src( get_post_thumbnail_id($lesson->ID), array( 200,200 ), false, '' );
$html .= '<ul>';
foreach( $lessons as $lesson ) {
$html .= '<li class="lesson-items" style="background: url(<?php echo $thumbimg[0]; ?>)>';
$html .= '<a href="' . esc_url( get_permalink( intval( $lesson->ID ) ) ) . '" title="' . esc_attr( get_the_title( intval( $lesson->ID ) ) ) . '">' . get_the_title( intval( $lesson->ID ) ) . '</a>';
$html .= '</li>';
// Build array of displayed lesson for exclusion later
$displayed_lessons[] = $lesson->ID;
}
$html .= '</ul>';
$html .= '</section>';
}
我似乎也无法让 style="background.." 像我想要的那样阅读 php。
【问题讨论】:
-
加载此页面时实际呈现的是什么?
-
它显示了特色帖子(课程),但特色图片代码($thumbimg)是我添加的
-
我的意思是当你加载页面时PHP实际生成的,显示一些代码
标签: php wordpress image background featured