2012-09-18 119 views
0

所以我有一个循环显示我的主页上的所有页面(不是职位)。我想修改循环,以便它只显示单个父页面的子项(页面ID号为116,仅供参考)。我应该如何修改下面的代码来做到这一点?在主页上显示一个父页面的孩子(Wordpress)

<?php query_posts('post_type=page&posts_per_page=-1'); ?> 
<?php if (have_posts()) : while (have_posts()) : the_post(); ?> 

    <a href="<?php the_permalink() ?>" 
    rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"> 
    <div> 

     <?php echo get_the_post_thumbnail($page->ID, 'thumbnail'); ?> 

      <div ><?php the_title(); ?> 
     </div> <!-- headlines-title --> 

    </div></a> 

<?php endwhile; endif; ?> 

也想补充一点,显示孙子也是OK ...

回答

0

改变航向,并得到了结果我想要这种方式:

<?php 
$pages = get_pages('child_of=129&sort_column=post_date&sort_order=desc'); 
$count = 0; 
foreach($pages as $page) 
{ 
$content = $page->post_content; 
?> 


<a href="<?php echo get_page_link($page->ID) ?>" > 
    <div > 


     <?php echo get_the_post_thumbnail($page->ID, 'thumbnail'); ?> 

    <div><?php echo $page->post_title ?> 
     </div> 
    </div></a> 



<?php } ?> 
0

试试这个

<?php query_posts('static=true&child_limit=10&child_of='.$id.'&order=ASC'); ?> 
<?php if(have_posts()) : while (have_posts()) : the_post(); ?> 
<a href="<?php the_permalink();?>"><?php the_title();?>:</a><?php the_excerpt(); ? > 
<?php endwhile; endif; ?> 

$ ID是您页ID

+0

把这个削减nt页面id,并且它根本不显示任何页面。 – user1631884

+0

对不起,你必须安装这个插件才能工作http://wordpress.org/extend/plugins/pjw-query-child-of/ – Hareesh

+0

找到了一个不需要安装插件的答案。不过,感谢您的帮助。 – user1631884

相关问题