2013-03-10 133 views
1

女士&先生們,男生&女孩,古茹,極客和所有年齡的天才。如何在wordpress中通過特定父頁面的子頁面調用信息?

我對我的wordpress主題有問題。

我正在爲有網上商店的公司創建一個網站。店鋪頁面的層次結構如下所示:


-Catagory頁
- 產品頁

一個類別頁面被稱爲其中有22頁ID「設計」是什麼我想在wordpress的側邊欄<aside>中做一個鏈接,顯示'design'頁面最新子頁面的標題和圖片。每個產品頁面都有一個使用名爲「Product_Image」的自定義字段定義的圖像。

我發現了這個代碼在stackoverflow上,我修改後顯示我需要的數據,但不是隻調用設計頁面的最新子頁面,而是調用整個站點的最新頁面。

<?php 
    $args=array(
    'showposts'=>1, 
    'post_type' => 'page', 
    'caller_get_posts'=>1 
    ); 
$my_query = new WP_Query($args); 
if($my_query->have_posts()) { 
    while ($my_query->have_posts()) : $my_query->the_post(); ?> 
    <div> 
     <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?> 
     <?php echo "<img src='" . get_post_meta($post->ID, "Product_Image", true) . "' />"; ?> 
     </a> 
    </div> 
    <?php 
    endwhile; 
} 
?> 

我對PHP完全陌生。我剛剛開始學習使用「Tutsplus - PHP基礎知識」。

任何人都可以幫助我修改此代碼,因此它只顯示設計頁的最新子頁面中的信息。

回答

1

您可以向查詢中添加一個新參數,以僅獲取作爲設計頁的子頁面的頁面。因此,修改$ args數組看起來像這樣:

$args=array(
    'showposts'=>1, 
    'post_type' => 'page', 
    'caller_get_posts'=>1, 
    'post_parent' => '22' // get pages that are children of the design page 
); 

原樣留下你的代碼的其餘部分,它應該工作。
爲了將來的參考,在這裏查看所有的WP_Query參數:http://codex.wordpress.org/Function_Reference/WP_Query#Parameters

+0

哇這麼簡單。非常感謝你。 我不能投票答覆,因爲我還沒有15的聲望。 – 2013-03-10 16:52:52

相關問題