You appear to be a bot. Output may be restricted
Description
Implement [bw_background] shortcodeDisplays an attached media image as the background image for the article Rather than displaying the image as a link we generate the CSS instead. This is slightly easier than using custom CSS since the author doesn't have to find the full URL of the file manually.
Usage
$string = bw_background( $atts, $content, $tag );
Parameters
- $atts
- ( array ) optional – shortcode parameters
- $content
- ( string ) optional – not expected
- $tag
- ( string ) optional – the shortcode tag
Returns
string generated HTMLTO DO
support multiple background imagesTO DO
support identification of the actual image ID to display rather than the parent So [bw_background] will be the equivalent of the first CSS specification below [bw_css] article { background: url("http://rowlandscastlewebdesign.com/phphants/files/2013/11/How-is-it-done.jpg" ) no-repeat; background-size: 100% auto; color: white; } a.bw_tree { color: white; text-shadow: 0 1px 2px #000;} article h3 { padding-top: 16%; } [/bw_css]Source
File name: oik-css/shortcodes/oik-background.phpLines:
1 to 30 of 30
function bw_background( $atts=null, $content=null, $tag=null ) { $atts['post_type'] = bw_array_get( $atts, "post_type", "attachment" ); $atts['post_mime_type'] = bw_array_get( $atts, 'post_mime_type', 'image' ); $atts['id'] = bw_array_get_from( $atts, "id,0", null ); if ( $atts['id'] === null ) { // Don't set the ID yet.. let get_thumbnail_src do it. } $atts['thumbnail'] = bw_array_get( $atts, "thumbnail", "full" ); oik_require( "includes/bw_posts.php" ); $thumbnail = bw_get_thumbnail_size( $atts ); //$posts = bw_get_posts(); //foreach ( $posts as $post ) { bw_trace2( $thumbnail, "thumbnail" ); list( $thumbnail, $width, $height ) = bw_get_thumbnail_src( $atts['id'], $thumbnail, $atts ); if ( $thumbnail ) { $selector = bw_array_get_from( $atts, "selector,1", null ); if ( !$selector ) { $selector = bw_default_selector_for_theme(); } stag( "style", null, null, kv( "type", "text/css" ) . kv( "media", "screen,print") ); $css = "$selector { background: url( \"$thumbnail\" ) no-repeat; background-size: 100% auto; background-origin: padding-box; }"; e( $css ); etag( "style" ); } else { BW_::p( __( "No thumbnail", "oik-css" ) ); } //} return( bw_ret() ); }View on GitHub View on Trac