2015-05-19 68 views
0

我有一個WordPress網站的父頁面下面的代碼。此頁面從子頁面抽取內容以便以摘要格式顯示。我所缺少的是如何從子頁面中拉取精選圖片網址的代碼。標題和內容被很好地拉動。有任何想法嗎?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

只需添加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 
} 
?> 
相關問題