Notices on church website

I had to do some fiddling today to get the new church website to display the notices. There are many plugins for Wordpress to do a huge number of vastly complicated things with posts and pages, but none for what I wanted. If you ever need the solution, this is it:

Install the media categories plugin, and add your notices as media, unattached to any page. (When WP 3.0 comes out, it may be better to switch to doing this using custom post types.) Add the following shortcode I wrote to your functions.php file, and then place [recent-media] on the page where you want the links to the notices. Tweak and style display as desired.


function recent_media() {
  $attachments =
    get_attachments_by_media_categories(
      array(
        'media_categories' => 'notices',
        'numberposts' => '5',
        'orderby' => 'title',
        'order' => 'DESC',
    ));
  $output = "";
  if ($attachments) {
    $output .= "<ul>";
    foreach ($attachments as $post) {
      $output .=
        '<li>
           <a href="'.
             wp_get_attachment_url($post->ID).
             "\">{$post->post_title}".
          "</a>
         </li>\n";
    }
    $output .= "</ul>";
  }
  return $output;
}
add_shortcode('recent-media', 'recent_media');