如何在wordpress边栏上显示带有wp_list_pages的子页面缩略图?

时间:2018-10-23 05:44:49

标签: php wordpress function sidebar children

需要在WordPress侧边栏上列出子页面的帮助,我已经创建了带有Feature Image的子页面,并且仅显示了具有 wp_list_pages 的列表,但是我不知道如何要在WordPress侧边栏上显示带有 wp_list_pages 的子页面缩略图,我找不到合适的示例来说明如何使用代码。请帮助我

以下是我的代码:

    <?php
        $ancestor_id = 1594;
$descendants = get_pages( array( 'child_of' => $ancestor_id ) );
$incl = '';

foreach ( $descendants as $page ) {
    if ( ( $page->post_parent == $ancestor_id )
        || ( $page->post_parent == $post->post_parent )
        || ( $page->post_parent == $post->ID )
    ) {
        $incl .= $page->ID . ",";
    }
}
?>

<ul>
    <?php
    wp_list_pages( array(
        'child_of'    => $ancestor_id,
        'include'     => $incl,
        'link_before' => '',
        'title_li'    => '',
        'sort_column' => 'menu_order'
    ) );
    ?>
</ul>

1 个答案:

答案 0 :(得分:0)

使用以下代码将显示Featured Image

    <?php
            $ancestor_id = 1594;
    ?>

    <ul>
       <?php
$mypages = get_pages('child_of='.$ancestor_id .'&sort_column=menu_order&parent=0');
if($mypages)
{
echo '<ul>';
foreach($mypages as $page)
{   
?>
<li>
<?php echo get_the_post_thumbnail($page->ID, 'thumbnail'); ?>
<h2><a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a></h2>
</li>
<?php
}
echo '</ul>';
}   
?>