might be that on the homepage I should not work with childpages but some other way? Maybe getting the entire site map / link tree and then hiding the rest?
Not sure how that would work if in a later stage another page is added though…
Please help, anyone?
I think I might have found something on this page…
http://codex.wordpress.org/Function_Reference/get_page_children
but I will have to see if this is what I am looking for and if I can translate it into what I need exactly.
hmmm cannot get this to work for me….
If I combine stuff from the example and what I already had, and I change the title at the get_page_by_title to the correct parent, I do get some result.
But nog just the children of that page, but from all pages…
I must be doing something wrong here I guess.
Can anyone help me?
This is what I now have:
<div id="childpages">
<?php
// Set up the objects needed
$my_wp_query = new WP_Query();
$all_wp_pages = $my_wp_query->query(array('post_type' => 'page'));
// Get the page as an Object
$portfolio = get_page_by_title('wat-biedt-het-paddenstoelenhuis');
// Filter through all pages and find Portfolio's children
$portfolio_children = get_page_children($portfolio->ID, $all_wp_pages);
?>
<?php if ( $portfolio_children ) : foreach ( $portfolio_children as $pageChild ) : setup_postdata( $pageChild ); ?>
<div class="child-thumb">
<div class="thumb"> <a href="<?php echo get_permalink($pageChild->ID); ?>" rel="bookmark"><?php echo get_the_post_thumbnail($pageChild->ID, 'thumbnail'); ?></a></div>
<div class="child-links">
<a href="<?php echo get_permalink($pageChild->ID); ?>" rel="bookmark"><h2><?php echo $pageChild->post_title; ?></h2></a>
<ul>
<?php
$howmany = 4;
$pages = wp_list_pages("echo=0&title_li=&parent=$pageChild->ID");
$pages_arr = explode("\n", $pages);
for($i=0;$i<$howmany;$i++){
echo $pages_arr[$i];
}
?>
</ul>
</div>
</div>
<?php endforeach; endif;
?>
</div>
Somehow I have the feeling this line doesn’t work:
$portfolio = get_page_by_title('wat-biedt-het-paddenstoelenhuis');
or it has something to do with:
$portfolio_children = get_page_children($portfolio->ID, $all_wp_pages);
because of the all_wp_pages maybe? But I haven’t got a clue what can be wrong and how to change it.
Please any help is appreciated!!!
Update:
If I use another page (lower in the hierarchy, Like Koken) it DOES work…
Maybe it has something to do with the long title?
I’ll check!
Still not completely there, but that helped!
Turns out I needed the title with spaces, and not the slug!
still have some problems:
- I want it to show just the children and not their children (do you call those grandchildren???) because they are already listed under their respective parents
- I lost my Order by menu, and haven’t a clue where to incorperate this in the new setup
So my search continues, but I am a bit farther now!
Anyone have any idea how to resolve my 2 new problems??
ok, my order by menu has been solved, by someone having the same problem on this forum
and then somewhere else on this forum I found the solution for the depth
For the order by menu I replaced:
$portfolio_children = get_page_children($portfolio->ID, $all_wp_pages);
with
$portfolio_children = get_pages('sort_column=menu_order&child_of=' . $portfolio->ID);
and the to resolve the depth issue I replaced it with:
$portfolio_children = get_pages('sort_column=menu_order&child_of=' . $portfolio->ID.'&parent='.$portfolio->ID);
the total code now is:
<div id="childpages">
<?php
// Set up the objects needed
$my_wp_query = new WP_Query();
$all_wp_pages = $my_wp_query->query(array('post_type' => 'page'));
// Get the page as an Object
$portfolio = get_page_by_title('wat biedt het paddenstoelenhuis');
// Filter through all pages and find Portfolio's children
$portfolio_children = get_pages('sort_column=menu_order&child_of=' . $portfolio->ID.'&parent='.$portfolio->ID);
?>
<?php if ( $portfolio_children ) : foreach ( $portfolio_children as $pageChild ) : setup_postdata( $pageChild ); ?>
<div class="child-thumb">
<div class="thumb"> <a href="<?php echo get_permalink($pageChild->ID); ?>" rel="bookmark"><?php echo get_the_post_thumbnail($pageChild->ID, 'thumbnail'); ?></a></div>
<div class="child-links">
<a href="<?php echo get_permalink($pageChild->ID); ?>" rel="bookmark"><h2><?php echo $pageChild->post_title; ?></h2></a>
<ul>
<?php
$howmany = 4;
$pages = wp_list_pages("echo=0&title_li=&parent=$pageChild->ID");
$pages_arr = explode("\n", $pages);
for($i=0;$i<$howmany;$i++){
echo $pages_arr[$i];
}
?>
</ul>
</div>
</div>
<?php endforeach; endif;
?>
</div>