• Resolved Linosa

    (@linosa)


    I’m using a bit of code in my theme to show child pages and grandchild pages of a page.
    It works perfect except for the fact that I want to show the content from the grandchildren and not the title (as it does today). I’ve tried to change “the_title” to “the_content” but that didn’t work.

    Any suggesitions?

    <?php
    
        $portfolioID = $post->ID;
    
        $portfolio_sections = array(
          'post_type' => 'page',
          'child_of' => $portfolioID,
          'sort_column' => 'menu_order',
          'sort_order' => 'ASC',
        );
    
        $sections = get_pages($portfolio_sections);
    
        $hierachical = array();
    
        if ( ! empty($sections) ) {
          foreach ( $sections as $section ) {
            if ( $section->post_parent == $portfolioID ) {
              if ( ! isset( $hierachical[$section->ID]) ) $hierachical[$section->ID] = array();
              $hierachical[$section->ID]['child'] = $section;
              $hierachical[$section->ID]['grandchildes'] = array();
            } else {
              if ( ! isset( $hierachical[$section->post_parent]) ) $hierachical[$section->post_parent] = array();
              $hierachical[$section->post_parent]['grandchildes'][] = $section;
            }
          }
          foreach ( $hierachical as $id => $hierachical_data ) {
            if ( ! isset($hierachical_data['child']) || ! is_object($hierachical_data['child']) ) continue;
            echo '<div class="grid">';
            echo '<h2>' . get_the_title($hierachical_data['child']->ID) . '</h2>';
            echo '<ul>';
            if ( isset($hierachical_data['grandchildes']) && ! empty($hierachical_data['grandchildes']) ) {
              foreach ( $hierachical_data['grandchildes'] as $grandchild ) {
                if ( ($grandchild->ID)) {
                  echo '<li>';
                  echo get_the_title($grandchild->ID);
                  echo '</li>';
                }
              }
            }
            echo '</ul>';
            echo '</div>';
          }
        } ?>
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Show the content insted of title in a list.’ is closed to new replies.