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
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="https://wordpress.stackexchange.com/questions/240419/<?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(); ?>