3

I'd like to create an "All Posts" page on the Ocean Bytes blog that contains an unordered list of all Titles of the posts to date, with each title hyperlinking to its blog post.

There appear to be several plugins that do something like this, but most do not list Wordpress 3.0+ as supported yet, or they want to subset the blog postings by Year and then Month which is not desired.

Any suggestions for the "best way"?

Thx.

3 Answers 3

3

Create a new template file and do this as the loop:

query_posts( array( 'posts_per_page' => -1, 'post_status' => 'publish' ) );
if( have_posts() ):
  echo '<ul>';
  while( have_posts() ):
    the_post();
    echo '<li><a href="';
    the_permalink();
    echo '">';
    the_title();
    echo '</a></li>';
  endwhile;
  echo '</ul>';
endif;
wp_reset_query();

Then just use that template for a page and it'll automatically generate the page. Check out the codex page for query_posts() for more information on how to change the query.

3

The "Best Way" would be with a custom page template. Just like index.php loops through all the posts, you can run a custom query to loop through everything and only echo the information you want (title, URL) to the browser.

Here are some good tutorials for building a custom page template:

1
  • Thanks for the links, which lead me to the solution I ended up with below. I'd upvote this answer but apparently I don't have enough SE mojo built up yet ;?)
    – cpuguru
    Commented Sep 1, 2010 at 12:33
3

I ended up creating a page template called "allposts-page.php" in the Twenty-Ten Themes folder containing the following code:

<?php
/**
 * Template Name: All Posts
 *
 * A custom page template for displaying all posts.
 *
 * The "Template Name:" bit above allows this to be selectable
 * from a dropdown menu on the edit page screen.
 *
 * @package WordPress
 * @subpackage Twenty_Ten
 * @since Twenty Ten 1.0
 */

get_header(); ?>

  <div id="container">
   <div id="content" role="main">
<h2>Archive of All Posts:</h2>
  <ul>
    <?php wp_get_archives('type=postbypost'); ?>
  </ul>


   </div><!-- #content -->
  </div><!-- #container -->

<?php get_footer(); ?>

I then created a new page using the Wordpress Admin system with a title of "All Posts" and selected the "All Posts" template from the drop-down. Didn't need to enter anything in the body.

The resulting page can be found via:

www.oceanbytes.org/all-posts/

The default for "wp_get_archives" is "monthly" but I chose "postbypost" as I wanted to just list all posts as on long list. More options can be found on the Wordpress site via Function Reference/wp get archives

1
  • Note: While the above worked with the previous self-hosted WP 3.0 site, I don't have access to create page templates on the now externally hosted WP 4.x site due to hosting restrictions. So the resulting page listed above does not run the PHP code above.
    – cpuguru
    Commented Oct 16, 2015 at 18:53

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.