将页面特色图片添加到foreach循环 [英] Add a pages featured image to a foreach loop

查看:119
本文介绍了将页面特色图片添加到foreach循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个foreach循环,该循环显示子页面的标题,内容和URL列表.我似乎无法显示精选图片!这就是我所拥有的:

I've got a foreach loop that is displaying a list of subpages Title, Content and URL. I can't seem to display the featured image though! Here's what I have:

<?php
$pageChildren = get_pages('sort_column=menu_order&hierarchical=0&child_of='.$post->ID);
if ( $pageChildren ) {
foreach ( $pageChildren as $pageChild ) {
echo '<div style="position:relative;float:left;width:100%;margin:0 0 20px 0;border-bottom:1px dashed #cdcdcd;padding:0 0 20px 0">';
//FEATURED IMAGE HERE
echo '<a class="newstitle" href="' . get_permalink($pageChild->ID) . '">' . $pageChild->post_title.'</a><br /><br />';
if (!empty($pageChild->post_content)){
        echo '<p>'.$pageChild->post_content.'</p> ';
        echo '<a class="readmore" href="' . get_permalink($pageChild->ID) . '" style="float:left">Read More &raquo;</a>';
    }
    echo '</div>';
}
}
?>

推荐答案

您必须使用

<?php echo get_the_post_thumbnail($pageChild->ID ); ?> 

获取帖子缩略图以及页面

to get the post thumbnail as well page

这篇关于将页面特色图片添加到foreach循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆