我试图通过分类法在simple_field中获取图像,但我不能理解它,如果我接受var_dump我得到标题和其他东西,如链接描述,但不是图像......有没有人知道如何访问此图片/ simple_field?
我正在使用wordpress和php,
$tt = get_terms('product_type', array());
foreach ($tt as $term) :
print $term->name. ": ";
$q = new WP_Query(array(
'post_type' => 'ep-produkter',
'post_status' => 'publish',
'posts_per_page' => -1, // = all of 'em
'tax_query' => array(
'taxonomy' => $term->taxonomy,
'terms' => array( $term->term_id ),
'field' => 'term_id',
),
));
$first = true;
foreach ($q->posts as $item) :
var_dump($item);
print '<a href="'.get_permalink($item->ID).'">'
.$item->post_title.'</a>';
//here i want to echo the img
endforeach;
endforeach;
答案 0 :(得分:1)
您可以在for循环中使用以下功能来打印帖子的特色图片:
//here i want to echo the img
echo get_the_post_thumbnail( $item->ID, 'thumbnail' );
或者,您可以使用img标签获取图片网址并显示图片:
//here i want to echo the img
$url = wp_get_attachment_url( get_post_thumbnail_id($item->ID) );
echo '<img src="$url" alt="" />';