WordPress.org

Ready to get started?Download WordPress

Forums

Display subpages with child of (2 posts)

  1. necroob
    Member
    Posted 1 year ago #

    Hi!
    I'm trying to display the subpages on a page and I use the code below. It works perfectly, but I need it changed a little.

    <?php
    	$page_ids = array();
    	$subpages = get_pages('depth=4&child_of='.$post->ID.'&sort_column=post_title');
    	if($subpages)foreach($subpages as $subpage) { $page_ids[] = $subpage->ID; } 
    
    	$subpages = new WP_Query( array(
    		'post_type' => 'page',
    		'post__in' => $page_ids,
    		'orderby' => 'title',
    		'paged' => get_query_var('paged')
    		));
    	$count = 0;
    	if($page_ids && $subpages->have_posts()) : ?>
    <ul class="product_list">
    <?php while($subpages->have_posts()) : $subpages->the_post(); ?>
    
    <li>
            <div class="product_layout">
      <div class="thumb1"><a href="<?php echo get_page_link($post->ID) ?>"><?php echo get_the_post_thumbnail($post->ID, 'thumbnail'); ?></a>
      <a href="<?php echo get_page_link($post->ID) ?>" title="<?php echo $post->post_title ?>"><?php $thetitle=$post->post_title; $getlength = strlen($thetitle);
    $thelength = 18;
    echo substr($thetitle, 0, $thelength);
    if ($getlength > $thelength) echo "..."; ?></a></div>
        <div class="bottom"></div> 
    
    </li>
    
    	<?php endwhile; ?>
     </ul>

    At some point I have Page1 with the SubPage1 whom has a SubSubPage1 with a SubSubSubPage1 and the code displays all of them,
    I want it to show me only the SubSubSubPage1 and I tried using
    depth but it doesn't work. I used it like that:

    <?php
    	$page_ids = array();
    	$subpages = get_pages('depth=4&child_of='.$post->ID.'&sort_column=post_title');
    	if($subpages)foreach($subpages as $subpage) { $page_ids[] = $subpage->ID; } 
    
    	$subpages = new WP_Query( array(
    		'post_type' => 'page',
    		'post__in' => $page_ids,
    		'orderby' => 'title',
    		'paged' => get_query_var('paged')
    		));
    	$count = 0;
    	if($page_ids && $subpages->have_posts()) : ?>

    Can someone help me?

  2. alchymyth
    Forum Moderator
    Posted 1 year ago #

    consider to post a job http://jobs.wordpress.net/

    imho, this idea in its complexity seems to be beyond the support capabilities of this forum.

    in general, you need to check with some coding which level of sub-sub-sub any of the child pages is, and only process those of the right sub-sub-sub level any further.

Topic Closed

This topic has been closed to new replies.

About this Topic