0

I want to display the content of all pages on a single page, with links to each page.

This might sound like a daft request, but it's useful for quickly reviewing what's available on a smallish site.

Using the code below, I can get most of the info I want, but don't know how to add the permalink.

<?php $pages = get_pages();
foreach ($pages as $page_data) {
$content = apply_filters('the_content', $page_data->post_content);
$title = $page_data->post_title;
$slug = $page_data->post_name;
echo $title;
echo $slug;
echo $content;}
?>

4 Answers 4

0

Try this code to show list of page content. Page title will be the link of that page.

$args = array(
    'post_type' => 'page',    //specifying post type
    'posts_per_page' => 10,  //No. of Pages to show
);

$loop = new WP_Query( $args );

while ( $loop->have_posts() ) : $loop->the_post();?>
<h3><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><font style="color:#666666;"><?php the_title();?></a></h3>
<?php    the_content(__('Continue Reading'));             
endwhile;
0
0

Try This:

<?php
    global $paged;  
        if( get_query_var( 'paged' ) ) {
            $paged = get_query_var( 'paged' );
        } elseif( get_query_var( 'page' ) ) {
            $paged = get_query_var( 'page' );
        } else {
            $paged = 1;
        }

        $args = array(
            'post_type'     => 'page',
            'paged'         => $paged,
        );

        $blog_query = new WP_Query($args);
    ?>

    <section>
        <?php if ( $blog_query->have_posts() ) : ?>
        <?php while ( $blog_query->have_posts() ) : $blog_query->the_post(); ?>
        <?php get_template_part( 'content-parts/content', get_post_format() ); ?>
        <?php endwhile; ?>
        <?php endif; ?>
    </section><!-- End #content -->
?>
0

As you have all the Page data stored in $page_data, you can pass the Page ID to the get_permalink(); to get the permalink of each page inside foreach loop.

$pages = get_pages();
if ( !empty( $pages ) ) :
    foreach ($pages as $page_data) {
        $content = apply_filters('the_content', $page_data->post_content);
        $title = $page_data->post_title;
        $slug = $page_data->post_name;
        echo '<a href="' . get_permalink( $page_data->ID ) . '">' . $title . '</a>';
        echo $slug;
        echo $content;
    }
endif;
-1

There is probably better ways to achieve what you are wanting, but to answer your question with what you have:

$permalink = get_the_permalink($page_data->ID);
0

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.