Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Hope it doesn't seem to shallow of a question, but I've searched the web as much as I've could and have not found anything similar yet.

:: Creating a regular post; How can I place a .mp3 link in a "custom-field", have that "custom-field" wrap the .mp3 in <a href=ex.mp3">Example</a> and place it as a <?php .. ?> in the single.php file.

It shouldn't be that difficult, at least from my perspective. Any help/tutorials will definitely be resourceful right now.

.....................

Appreciate the reply @johnsardine . I pretty much went with the basics of WP's Codex on Custom Fields. This is what I ultimately came up with (Note: this is going in The Loop via single.php - as I only want this on posts)

<a class="htrack" tabindex="1" type="audio/mpeg" title="<?php the_title(); ?>" href="<?php $key="mp3link"; echo get_post_meta($post->ID, $key, true); ?>" rel="nofollow"><?php the_title(); ?></a>

mp3link is used for the "Custom Field" key and of course, a regular URL to a Mp3 link (ie. http://filehost[.]com/song.mp3) is the value.

On the final end I'm wrapping it into Yahoo's Web Player (htrack, tabindex, etc.). All in all, the Custom Field/Link/Link Title/and Yahoo are all working well together, I just can't figure out how to get the img. The code above omits the <img src=... /> because every option I've used to get the thumbnail of posts, have not worked. If you can help me out on that, it'd be much appreciated as well.

Example of what I'm meaning:

<a class="htrack" tabindex="1" type="audio/mpeg" title="<?php the_title(); ?>" href="<?php $key="mp3link"; echo get_post_meta($post->ID, $key, true); ?>" rel="nofollow">
**<img src="unfiltered html to image.jpg" />**
<?php the_title(); ?></a>

Or Am I trying to include the image wrong all-together? Thanks in advance.

share|improve this question
add comment

1 Answer

First you need to create that custom field and choose an apropriate name, then you can paste your link and save the post.

After that, you must open your single.php file (or the file where you want the link to exist) and insert the following inside the loop:

<?php

//first i select which custom field i want to get, i called it "my-custom-field-name" but you can change at your desire,
//it just needs to match the one you inserted in the post editor
$music_file = get_post_meta($post->ID, 'my-custom-field-name', true);

//here i define a title for the hyperlink, if you want to display a custom title, just define another custom field and adjust the name below
$music_name = get_post_meta($post->ID, 'my-custom-field-title', true);

//now i check if that field has something, that way if a particular post does not contain a link, no unnecessary html will be added
if ($music_file) {
    echo '<a href="'. $music_file .'" title="'. $music_name .'">'. $music_name .'</a>';
}

?>

the code is pretty straightforward, but if you encounter any problems please let me know.

You can check more information about the get_post_meta function here.

EDIT:

To get the post thumbnail you must use the_post_thumbnail, read more about it here: the_post_thumbnail

First if your theme already uses the post thumbnails, you just include this <?php the_post_thumbnail( 'SIZE'); ?> in the size you can have: thumbnail, medium, large, full or a custom size defined in functions.php.

If your theme does not support the post thumbnails you must add this to functions.php

if ( function_exists( 'add_theme_support' ) ) { 
add_theme_support( 'post-thumbnails' ); 
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.