Auto sub content in WordPress

Adding the headings of direct children of the page to the page automatically. Just add the code below to the end of the content-page.php file in your theme directory.

<?php
        $mypages = get_pages( array( 'parent' => $post->ID, 
            'sort_column' => 'post_date', 
            'sort_order' => 'desc' ) ); 
        foreach( $mypages as $page ) {
                $content = $page->post_content;
                if ( ! $content ) // Check for empty page                
                continue;
                $content = apply_filters( 'the_content', $content );
?>
                <h2><a href="<?php echo get_page_link( $page->ID );?>"> <?php echo $page->post_title; ?></a></h2>
                <div class="entry">
                        <?php// echo $content; ?>
                </div>
<?php
}
?>

 

Sharing...

Leave a Reply