• Resolved omniafausta

    (@omniafausta)


    I am making a site for a client in WordPress, and the most important part of the site are the activities they are organizing.
    On the parent page of all the activities I now have made what I want for that page: an overview of the subpages of that page. (after combining some stuff I found on the web, I can’t write php myself, just read a bit, usually enough to make some adjustments)

    Here is the link to that page:
    http://www.hetpaddenstoelenhuis.nl/wordpress/wat-biedt-het-paddenstoelenhuis/

    Here is the code I used for that:

    <div id="childpages">
    <?php
    $child_pages = $wpdb->get_results("SELECT *    FROM $wpdb->posts WHERE post_parent = ".$post->ID."    AND post_type = 'page' ORDER BY menu_order", 'OBJECT');    ?>
    <?php if ( $child_pages ) : foreach ( $child_pages 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, 'medium'); ?></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>

    So far so good… But now I want to show that overview also on the homepage, so people can see an overview of the activities immediately when the arrive on the site.
    But… of course these child pages are not the child pages of the homepage, so this code results in nothing.
    Is there a way to change this code for the homepage so it shows the same overview (but other text besides it, so I cannot make this parent page my homepage)

    Hope you can help (and dumb it down a bit for me if necesarry)
    Thanks for your time!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter omniafausta

    (@omniafausta)

    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?

    Thread Starter omniafausta

    (@omniafausta)

    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.

    Thread Starter omniafausta

    (@omniafausta)

    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!

    Thread Starter omniafausta

    (@omniafausta)

    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??

    Thread Starter omniafausta

    (@omniafausta)

    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>

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘showing childpages of another than the current page’ is closed to new replies.