Question

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.

Was it helpful?

Solution 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

OTHER TIPS

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.

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:

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top