Support » Fixing WordPress » Enclosure Feild Output as a Link

  • Resolved Orin


    I have recently been trying to <?php?> my way into outputting links on the main page for enclosures. At issue is the fact that if an enclosure value is called (as either an array or a string with get_post_custom_values or get_post_meta, respectively) it returns all the information regardless of line breaks. This of course nullifies links since it includes the filesize and mimetype. I know it’s possible to parse the line breaks or otherwise the “url= length= type=” in the feed itself would be impossible.

    …but I have no idea how to do such a thing.

Viewing 6 replies - 1 through 6 (of 6 total)
  • *bump*, please

    No one knows the answer to such a question?

    Bah. After much investigation I’ve solved this myself. I did it by finding the rss_enclosure function in feed-functions.php and modifying it, since it’s not usable in html. Here’s how I wrote mine:

    <?php if (get_post_custom_values(enclosure)!='') {

    while(list($key, $val) = each( get_post_custom() )) {
    if($key == 'enclosure') {
    if (is_array($val)) {
    foreach($val as $enc) {
    $enclosure = split( "n", $enc );
    '<a href="'.trim( htmlspecialchars($enclosure[0]) ).'"
    title="Download '.trim($enclosure[3]).'">
    ' .trim($enclosure[3]). '</a>';

    Line breaks have been added for clarity. Note that I added a fourth attribute for my enclosure field ($enclosure[3]) where I write the custom title that will appear on the page. This code is currently in use on a torrent podcasting blog I do.

    For anyone else that seeks to do this (assumably common) task, I hope I’ve been a help.

    I think you have modified the wrong code. You don’t really want a link in your RSS feed.

    Here is a hack that I have done to place the enclosure link under the title of a post.

    Put this function into the template-functions-post.php file

    function the_enclosure() {
    global $id;
    $encl = &get_post_meta($id,'enclosure',true);
    return "Direct <a href=\"".$encl."\">Link</a> to the show";

    Then, put this code in your theme files inside the post loop, themes\default\single.php and themes\default\page.php and themes\default\index.php.

    <?php echo the_enclosure(); ?>

    This is exactly what I want to do, but I can’t get either of your solutions to work. are you both using 1.5?

    Orin, what i’m trying to do is dynamically build a xspf playlist based on the linked enclosure in my post. I’m then trying to link a flash mp3 player to that playlist.

    So right now I have a seperate playlist.php file that I’m trying to load with the url of the mp3 enclosure attached to my post. I’m not having a lot of luck getting your solutions to work. any help is appreciated.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Enclosure Feild Output as a Link’ is closed to new replies.