像@jdm2112一样,我不是Gensis用户,但这里有一种检索特征图像的替代方法。我使用这种方法是因为它提供了更多的功能来改变特征图像(即缩略图大小)。
可以将这些函数添加到函数中。php文件。
public function get_featured_image_id() {
return (int) $this->get_meta( \'_thumbnail_id\' );
}
/**
* Get the featured image url for the given featured image id
*
* @param string $size
* @return string|false
*/
public function get_featured_image_url( $size = \'full\' ) {
$attachment_id = $this->get_featured_image_id();
if ( ! $attachment_id ) {
return false;
}
$src = wp_get_attachment_image_src( $attachment_id, $size );
if ( ! $src ) {
return false;
}
return $src[0];
}
/**
* Get the HTML for the featured image html
*
* @return string
*/
public function get_featured_image_html( $size = \'full\' ) {
if ( $featured_image_id = $this->get_featured_image_id() ) {
return wp_get_attachment_image( $featured_image_id, $size, \'\' );
} else {
return \'\';
}
}
WordPress“循环”中的用例
echo esc_url( $post->get_featured_image_url( the_id() ) );