Enclosures in the new WordPress 1.5

Well, there is some support for enclosures right out of the box in the new release of WordPress, but it could still handle a bit of help. The way I hacked this into the old version was to insert two special custom fields and then wire the templates to scan for these and output the right bits of HTML and RSS when each post was printed.

WordPress 1.5 handles things a bit differently: it will scan the post for links to urls which appear to be audio files, and then inserts a custom enclosure field in the database with the url, size and type included as a string. But since it already thinks that the URL is linked in the post, it does nothing to make the link stand out in any way.

When I updated from 1.2, I converted each of my custom fields into a format which was compatible with the new scheme, but I was then left with a dilemma: go back and patch the text of all 52 entries so that it included a link (ugly) or go ahead and modify the templates to include a customized link. I chose the latter. I found out with a bit of work that code that looks like the following works. I include it just after any template emits the_content for a post.

$encs = get_enclosed($post_ID) ;
if ($encs) {
    echo '<div class="podcast">' ;
    foreach ($encs as $enc) {
        echo '<a href="'.$enc.'">Click here</a> to listen to the podcast.' ;
    }
    echo '</div>';
}

Nothing too exciting, but might prove useful to you in your work.

3 thoughts on “Enclosures in the new WordPress 1.5

  1. Pingback: Blogging Pro » WordPress Hack: Enclosures Wordpress 1.5

  2. Brian R.

    How could we get this code to repeate itself so it creates a list of all the enclosures (thus the podcasts) on a site? A audio archive page of sorts.

    Editor’s note: I’ve got a simple hack that finds all the enclosures and puts a list of the five most recent entries that contain enclosures that I use to generate the sidebar you can now see on my site. It’s pretty straightforward, I’ll post it in the next day or two.

  3. Yvonne

    Can you tell me what files i need to edit and add the code to?

    Thanks.

    Editor’s note: I added the code to index.php, in wp-content/themes/brainwagon (brainwagon is, predictably, the name of my theme).

Comments are closed.