1

I have run into an interesting issue.

My intention is to have a front-page.php that displays a list of pages, with titles and content (some of which may be truncated with tag.

I have augmented the below filtered arguments to do this, but have been unable to prevent it from displaying the full content each time:

https://codex.wordpress.org/Function_Reference/get_pages#Displaying_Child_pages_of_the_current_page_in_post_format

Here's the code:

            <?php 
                $args = array(
                'sort_order' => 'asc',
                'sort_column' => 'post_title',
                'hierarchical' => 1,
                'post_type' => 'page',
                'post_status' => 'publish'
); 
$pages = get_pages($args);
foreach( $pages 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>
    <section class="<?php echo $page->post_name; ?>">

    <div class="entry"><?php echo $content; ?></div>
    </section>
<?php
}   
?> 

Now, I'm aware that:

<?php global $more; $more = 0;  ?>

is the purported solution to this, but it does not appear to work, regardless of placement within the code.

Has anyone experienced similar and solved this? I further realise that using a WP Query with post type 'page' is a potential workaround, but have found that solution is not without it's own issues, like the ability to filter out sub pages.

Any advice will be greatly appreciated. I was unable to find a solution to this with a decent amount of interweb hunting.

1

1 Answer 1

0

Here's the code I am using (successfully):

   $pages = get_pages($args);
    foreach( $pages as $page ) {    

    $content = $page->post_content;
    // Get content parts
    $content_parts = get_extended( $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>
    <section class="<?php echo $page->post_name; ?>">

    <div class="entry"><?php echo $content_parts['main']; ?></div>
    </section>
<?php
}   

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.