您好我正在尝试为每个页面提供我的页面精选图像。我已经设置了我的特色图像,但似乎无法显示特色图像。我试图从这些(如: Get featured image of a page (no post) in Wordpress
Add a pages featured image to a foreach loop
Wordpress Display Child page data: Title, featured image and custom field
Get Featured Image of Pages - WordPress
但仍未能将我的精选图片拿出来。当我试图检索我的页面数据时,似乎没有存储在数组中的特色图像URL。请帮忙。
<?php
$menuLocations = get_nav_menu_locations();
$menuID = $menuLocations['introBlock_menu'];
$primaryNav = wp_get_nav_menu_items($menuID);
foreach ( $primaryNav as $navItem ) {
?>
<div class="col-md-4">
<div class="intro-block">
<!-- This is where I am trying to get the featured image url -->
<div class="intro-block-inner">
<h2>
<?php
echo '<li style="list-style-type: none;"><a style="text-decoration: none;" href="'.$navItem->url.'" title="'.$navItem->title.'">'.$navItem->title.'</a></li></div></div></div>';
}
?>
</h2>
答案 0 :(得分:0)
首先创建图像URL的绝对路径并在需要的地方回显它。请查看以下示例:
<?php
$url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
?>
<div class="col-md-4">
<div class="intro-block">
<img src="<?php echo $url; ?>">
<div class="intro-block-inner">
<h2>Your Heading Element</h2>
</div>
</div>
</div>