I'm trying to get my code to:
- Get a post's thumbnail url
- or (if no thumbnail there) to
- Echo a default url
I'm not sure if I am going the easiest way or right way about this.
This is the code so far. $postid being the attribute for the id of the post I want the url from.
<?php
// Add Shortcode
function friend_pic( $atts , $content = null ) {
// Attributes
extract( shortcode_atts(
array(
'postid' => '',
), $atts,
'f-p'
)
);
$postid = $atts['postid'];
ob_start();
// shortcode contents from here
echo "<img src=\"";
if ( $postid ) {
$thumb_url = wp_get_attachment_url( get_post_thumbnail_id( $postid, 'thumbnail', false) );
$thumb_url = $thumb_url[0];
}else{
echo "http://www.website.com/default.jpeg";
}
echo "\">";
// Shortcode edit ends here
$output = ob_get_contents();
ob_end_clean();
/// FINAL OUTPUT ////
return $output;
}
add_shortcode( 'f-p', 'friend_pic' );
**Aditional Details* The point of this is to display the pictures of my friends by using a shortcode in my posts. The pages of my website are about my family and friends, and when I want to reference one I just wanna show the thumb of their page, its their picture, and if there isnt a thumb then show a default picture (a N/A picture).