Last active
February 13, 2016 19:49
-
-
Save twentyfortysix/49c6b9dc43502ee356d5 to your computer and use it in GitHub Desktop.
WP - alternative eresponsive background images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// picture ids: array(1, 2, 3) | |
// $queries = array( | |
// array('large_screens','min-width: 1450px'), | |
// array('medium','max-width: 480px'), | |
// array('large','') | |
// ); | |
function responsive_background_pictures($id_array, $queries){ | |
$with_euery = ''; | |
$without_euery = ''; | |
// for each style resolution | |
foreach($queries as $query){ | |
$each_style = ''; | |
// for each picture | |
foreach ($id_array as $id) { | |
$att = wp_get_attachment_image_src($id , $query[0]); | |
$each_style .= '#img_'.$id.'{background-image:url('.$att[0].');}'; | |
} | |
// if the query has no media query resolution set, print it out as it is | |
if(!empty($query[1])){ | |
$with_euery .= '@media only screen and ('.$query[1].') {'; | |
$with_euery .= $each_style; | |
$with_euery .= "}\n"; | |
}else{ | |
$without_euery .= $each_style; | |
} | |
} | |
return $without_euery."\n".$with_euery."\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment