Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.96 KB | None | 0 0
  1. <?php
  2.    
  3.     global $post;
  4.  
  5.     function showSubpages( $post_id, $current_level ) {
  6.    
  7.     $subpages = get_posts( array(
  8.         'post_type' =>'page',
  9.         'posts_per_page' =>-1,
  10.         'post_parent' => $post_id,
  11.         'order_by' => 'title',
  12.         'order' => 'ASC' ) );
  13.  
  14.     if ( empty($subpages) ) {
  15.         return;
  16.     }
  17.  
  18.     echo '<ul class="subpages level-'.$current_level.'-subpages">';
  19.  
  20.     foreach ($subpages as $page) {
  21.  
  22.  
  23.         $image = get_the_post_thumbnail( $page->ID, 'thumbnail' );
  24.  
  25.         echo '<li>';
  26.  
  27.         echo '<a href="'.get_permalink($page->ID).'">';
  28.        
  29.         echo '<span>';
  30.         echo apply_filters( 'the_title', $page->post_title );
  31.         echo '</span>';
  32.  
  33.         echo '<div class="feature_image">' . $image . '</div>';
  34.         echo '</a>';
  35.  
  36.         showSubpages( $page->ID, $current_level+1 );
  37.  
  38.             echo '</li>';
  39.  
  40.         }
  41.  
  42.     echo '</ul>';
  43.  
  44.     }
  45.  
  46.     showSubpages( $post->ID, 1 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement