我在WordPress网站的父页面上有以下代码。此页面从子页面中提取内容以在其上以摘要格式显示。我缺少的是如何从子页面中提取特色图像URL的代码。标题和内容很好。有什么想法吗?
<?php
$mypages = get_pages( array( 'child_of' => $post->ID, 'sort_column' => 'post_date', 'sort_order' => 'desc' ) );
foreach( $mypages as $page ) {
$content = $page->post_content;
if ( ! $content ) // Check for empty page
continue;
$content = apply_filters( 'the_content', $content );
?>
<h2><a href="<?php echo get_page_link( $page->ID ); ?>"><?php echo $page->post_title; ?></a></h2>
<div class="entry"><?php echo $content; ?></div>
<?php
}
?>
答案 0 :(得分:0)
只需添加the_post_thumbnail();
即可检索精选图片。有关进一步的自定义,请参阅此Featured Image Codex
因此修改后的代码将是:
<?php
$mypages = get_pages( array( 'child_of' => $post->ID, 'sort_column' => 'post_date', 'sort_order' => 'desc' ) );
foreach( $mypages as $page ) {
$content = $page->post_content;
if ( ! $content ) // Check for empty page
continue;
$content = apply_filters( 'the_content', $content );
?>
<h2><a href="<?php echo get_page_link( $page->ID ); ?>"><?php echo $page->post_title; ?></a></h2>
<?php the_post_thumbnail(); ?> // Gets the featured image
<div class="entry"><?php echo $content; ?></div>
<?php
}
?>