$size,
'url' => $img_meta[0],
'w' => $img_meta[1],
'h' => $img_meta[2],
'h/w' => round($img_meta[2]/$img_meta[1], 3)
);
}
return $sircontheme_image_formats[$attachment_id];
}
//Try really hard to get a alt-tag for an image
function get_image_alt($attachment_id){
$img_alt_text = get_post_meta($attachment_id, '_wp_attachment_image_alt', 1);
if(!$img_alt_text){
$post = get_post($attachment_id);
if($post->excerpt){
$img_alt_text = $post->post_excerpt;
}else{
$img_alt_text = $post->post_title;
}
}
return $img_alt_text;
}
//Just a post thumbnail, simply
function get_sircontheme_featured_image($size = 'hd', $post_id = false){
if(!$post_id){$post_id = get_the_ID();}
if(!has_post_thumbnail($post_id)){return '';}
return ''.get_the_post_thumbnail($post_id, $size).'';
}
function sircontheme_featured_image($size = 'hd', $post_id = false){
echo get_sircontheme_featured_image($size, $post_id);
}
//Creates a possibly optimized content image. Default size is the largest resized one
function get_sircontheme_dynamic_featured($size = false, $post_id = false){
if(!$post_id){$post_id = get_the_ID();}
if(!has_post_thumbnail($post_id)){
return ''; //No featured image
}
//Fallback to the nicest size
if(!$size){$size = 'hd';}
$attachment_id = get_post_thumbnail_id($post_id);
//We got attachment id, now get the dynamic output for this specific attachment id
return get_sircontheme_dynamic_imageoutput($attachment_id);
}
function sircontheme_dynamic_featured($size = false, $post_id = false){
echo get_sircontheme_dynamic_featured($size, $post_id);
}
//get output for a specific attachment id!
function get_sircontheme_dynamic_imageoutput($attachment_id, $background_only = true){
$error_figure = '';
if(!is_numeric($attachment_id)){
//MISSING ID!
return sprintf($error_figure, 'ERROR-MISSING-ID', ' is missing');
}else if(get_post_type($attachment_id) !== 'attachment'){
//NOT AN IMAGE/ATTACHMENT!
return sprintf($error_figure, 'ERROR-NOT-ATTACHMENT', ' is not an attachment');
}
$img_formats = get_sircontheme_image_formats($attachment_id);
$data_formats = array();
$format_names = array();
foreach($img_formats as $format){
$format_name = 'data-'.$format['id'];
$format_names[] = $format_name;
$data_formats[$format_name] = array();
foreach($format as $k => $v){
if($k === 'id'){continue;}
$data_formats[$format_name][] = $v;
}
}
$data_outputs = array();
foreach($data_formats as $name => $vals){
$data_outputs[] = $name.'="'.implode(';', $vals).'"';
}
//Concatenate a fully informative data-string
$data_output = implode(' ', $data_outputs);
$data_output .= ' data-formatnames="'.implode(';', $format_names).'"';
$img_alt_txt = get_image_alt($attachment_id);
$img_alt = 'alt="'.$img_alt_txt.'"';
//The following is actually obsoleted now.. kept for ability to add own custom functionality with javascript. Maybe use css..?
$background_only = $background_only ? 'data-only_background_image="1"' : '';
$js_friendly_img = '
';
$fallback_noscript_img = '';
//Fallback img
$oldschool_figure = get_sircontheme_featured_image('large', $post_id);
$fallback_noscript_img = '';
/* who cares .. ? .. Should we care? */
return $js_friendly_img.$fallback_noscript_img;
}
//Get a linked image. Link goes to the post/page. If no image, then no output
function get_sircontheme_dynamic_featured_link($size = false, $post_id = false){
$img_output = get_sircontheme_dynamic_featured($size, $post_id);
if(!$img_output){return '';}
$permalink = get_permalink($post_id);
return ''.$img_output.'';
}
function sircontheme_dynamic_featured_link($size = false, $post_id = false){
echo get_sircontheme_dynamic_featured_link($size, $post_id);
}
/****
FULLFEATURE BACKGROUND
---------------------------------------------------------------------------- */
//You can disable the auto forced background, if you
function sircontheme_disable_background(){
global $sircontheme_disable_background;
$sircontheme_disable_background = true;
}
function sircontheme_background_disabled(){
global $sircontheme_disable_background;
return (isset($sircontheme_disable_background) && $sircontheme_disable_background === true);
}
function sircontheme_fantastic_background(){
//Early abort?
if(sircontheme_background_disabled()){
return; //EARLY ABORT
}
//All is good, proceed!
if(is_single() || is_page() || is_404()){
//Get single page/post background image( or gallery?)
rewind_posts(); the_post();
$img_id = get_sircontheme_postdata('fullsizebg-id');
$img = get_sircontheme_dynamic_imageoutput($img_id);
}
if($img){
echo '
'.$img.'
';
}
}
?>