Results 1 to 9 of 9

Thread: Audio RSS enclosure problem

  1. #1
    bryan868 is offline Hello World
    Join Date
    May 2010
    Posts
    10

    Default Audio RSS enclosure problem

    So I have a client with a website for their podcast. To make it easy, I just have them upload their audio file to a post, then I use get_children to grab the audio attachment and display it where I want on the page. That way they don't have to deal with custom fields or inserting code or anything like that.

    Only problem... WP will only auto-create the audio enclosure in the RSS feed if you have the mp3 linked from the post content. Since I'm using attachments, it won't auto-create the enclosure, thus no RSS feed w/audio! Any ideas?

  2. #2
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,801

    Default

    You could add the audio enclosure into an excerpt, and only display excerpts in your RSS feed.

  3. #3
    bryan868 is offline Hello World
    Join Date
    May 2010
    Posts
    10

    Default

    Right, but wouldn't that still be creating an extra step for the client? They'd have to copy/paste into the excerpt.

  4. #4
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,801

    Default

    How about auto-creating the excerpt on publishing a post. That way you can automatically add the audio enclosure to the end of each excerpt without your client needing to do anything. They wouldn't even need to know there was an excerpt being used if you hid the excerpt panel from their view.

  5. #5
    bryan868 is offline Hello World
    Join Date
    May 2010
    Posts
    10

    Default

    That's a good idea. I could also auto-create a custom field for the enclosure. Only prob is the client already created 30+ posts, so I'd have to go back and manually add it to those.

    Here's what I ended up doing, though I'm open to a more elegant solution! Opened /wp-includes/feed-rss2.php. Replaced the enclosure tag with:

    Code:
    <?php $mp3s = get_children('numberposts=-1&post_type=attachment&post_mime_type=audio&post_parent='.$post->ID); if (!empty($mp3s)) : ?>
    
    <?php foreach($mp3s as $mp3) : ?>
    
    <?php $mp3url = $mp3->guid; $mp3header = get_headers($mp3url, 1); $mp3size = $mp3header['Content-Length']; ?>
    
    <enclosure url="<?php echo $mp3url; ?>" length="<?php echo $mp3size; ?>" type="audio/mpeg" />
    
    <?php endforeach; ?>
    <?php endif; ?>

  6. #6
    Otto's Avatar
    Otto is offline On The Rocks
    Join Date
    Apr 2009
    Location
    Memphis, TN
    Posts
    865

    Default

    Seems complicated. Just have them add the mp3 file to the post as a link, then use a plugin or something to convert that into the player.

    This isn't really an extra step. When you do the upload of the MP3 file to the post, then there's a button that adds it right into the post. All they have to do is click that and a link to the MP3 file gets inserted. Since the link is now in the post, the enclosure works properly. Then you just change the link into a player on display.

    Example way of doing this here: http://ottopress.com/2010/how-to-add...rdpress-posts/

  7. #7
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,801

    Default

    Quote Originally Posted by bryan868 View Post
    Opened /wp-includes/feed-rss2.php. Replaced ...
    Bad idea. You should never modify core files like that. It'll seriously screw with your update path.

    My idea above would work, although I'd still be inclined to use Otto's suggestion above even though it doesn't quite meet your specifications since it requires an extra step by the end-user.

  8. #8
    Otto's Avatar
    Otto is offline On The Rocks
    Join Date
    Apr 2009
    Location
    Memphis, TN
    Posts
    865

    Default

    Quote Originally Posted by bryan868 View Post
    Here's what I ended up doing, though I'm open to a more elegant solution! Opened /wp-includes/feed-rss2.php. Replaced the enclosure tag with:
    Better way to do this exact same thing:

    PHP Code:
    add_feed('rss2''my_custom_feed');

    function 
    my_custom_feed$for_comments ) {
        if ( 
    $for_comments )
            
    load_templateABSPATH WPINC '/feed-rss2-comments.php' );
        else
            
    load_template'/path/to/my/rss2.php' );

    Then make a copy of the feed-rss2.php file, with your modifications, and have it call that file instead.

  9. #9
    Ryan's Avatar
    Ryan is offline WordPress Legend
    Join Date
    Jan 2009
    Location
    New Zealand
    Posts
    2,801

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •