2

How to list all titles of posts on a specific page?

I like to show my titles of posts on a specific page. It is more effective to get know what author have written than scroll all pages or navigate using archive widget.

I have made page template for my Twenty Fifteen child theme, but I don't know that code I need to show titles with links to posts.

1 Answer 1

1

Paste this into your page template. It will output a list of all posts (without pagination).

<?php
// the query
$all_posts = new WP_Query( array( 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => -1 ) );

if ( $all_posts->have_posts() ) :
?>

  <ul>
    <?php while ( $all_posts->have_posts() ) : $all_posts->the_post(); ?>
      <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endwhile; ?>
  </ul>

<?php else : ?>
  <p><?php _e( 'Sorry, no posts were found.' ); ?></p>
<?php endif; ?>

<?php wp_reset_postdata(); ?>
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.