2013-03-10 132 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

相关问题