WordPress posts index

This one’s more for my benefit than The Internet At Large, but I’ve just written a quick bit of php into a new wordpress page that displays an index of all wordpress posts I’ve made, organised by category. There’s a link to the index in my sidebar for when I forget where I’ve put it. I’ve briefly fiddled with a few plugins to do this, but they were all far too verbose to be useful.

To be honest, the main reason I did this was to avoid having to use Google to find my own Cookies Recipe..

The code I’ve used is below, I’m sure some people who know more PHP than I could improve it somewhat, but it does the job. To use it yourself, just copy and paste into a new page on your wordpress site, add <?php> tags and a php execute plugin and you’re away.

  $categories = get_categories('orderby=name');
  foreach($categories as $thisCategory) {
    $thesePosts = get_posts(array('numberposts' => -1, 
                                              'category' => $thisCategory->cat_ID,
                                              'orderby' => 'title',
                                              'order' => 'ASC'));
    echo ('<h2>' . $thisCategory->cat_name . "</h2>\n");
    foreach($thesePosts as $thisPost) {
      echo ('<a href="' . get_permalink($thisPost->ID) . '">' . 
              $thisPost->post_title . '</a> ('. 
              date('j M Y', strtotime($thisPost->post_date)) .
              ")<br />\n");