2012-06-28 10 views
0

基本上我想獲得父頁的畫廊,我一直在玩query_posts做到這一點,下面的代碼似乎讓我更接近我需要的東西,但它實際上是從其他地方獲得附件不僅僅是當前頁面的父頁面,?:如何僅通過query_posts獲取父頁面的附件?

<?php 
$args = array('post_type' => 'attachment', 
    'numberposts' => -1, 
    'post_status' => null, 
    'post_parent' => 0, 
    'order_by' => 'menu_order', 
    'order' => 'ASC'); 
$attachments = get_posts($args); 
if($attachments) 
{ 
    echo '<ul class="imagelist">'; 
    foreach($attachments as $attachment) 
{ 
echo '<li>'; 
$large = wp_get_attachment_image_src($attachment->ID, 'large'); 
$thumb = wp_get_attachment_image($attachment->ID, 'thumbnail'); 
echo '<a href="'. $large[0] .'">' . $thumb . '</a>'; 
echo '</li>'; 
} 
echo '</ul>'; 
} 
?> 

回答

1

你應該已經建立post_parent當前的後父ID的任何一個:

global $post; 
$args = array(
    'post_type' => 'attachment', 
    'numberposts' => -1, 
    'post_status' => null, 
    'post_parent' => $post->post_parent, 
    'order_by' => 'menu_order', 
    'order' => 'ASC' 
); 
+0

如果我你有什麼建議,我得到附着在圖像當前頁面。我沒有得到父圖像,因爲我希望它:( –

+0

對不起,沒有足夠的閱讀足夠的。現在改變幾行,保持好。 –

+0

輝煌!這就是我一直在尋找,非常感謝 –

相關問題