[oik] plugins.com

WordPress plugins and themes

  • Home
  • About
    • lazy shortcodes
    • smart shortcodes
    • oik base plugin
      • oik – donate
      • oik PayPal buttons
      • oik installation
      • oik Button Shortcode button
      • oik changelog
      • oik FAQ
      • oik plugins on SVN
      • oik plugins on GitHub
  • Plugins
    • oik base plugin
    • FREE oik plugins
    • WordPress plugins
    • Premium oik plugins
    • Bespoke oik plugins
  • Shortcodes
    • Shortcode examples
  • Blocks
    • Block examples
  • APIs
    • ALL action and filter hooks
  • Blog

bw_background() – Implement [bw_background] shortcode

Description

Implement [bw_background] shortcode

Displays 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 HTML

TO DO

support multiple background images

TO 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.php
Lines:
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

Called by

1 to 3 of 3
  • Tests_shortcodes_oik_background::test_bw_background() – Test [bw_background] shortcode with a thumbnail attached to the selected post
  • Tests_shortcodes_oik_background::test_bw_background_no_thumbnail() – Test [bw_background] shortcode with no thumbnail attached to the selected post
  • Tests_shortcodes_oik_background::test_bw_background_no_thumbnail_bb_BB() – Test [bw_background] shortcode with no thumbnail attached to the selected post – bb_BB lang

Invoked by

    Calls

    1 to 8 of 8
    • BW_::p() – Outputs a paragraph of translated text
    • bw_array_get() – Return the array[index] or array->index (for an object) or a default value if not set
    • bw_default_selector_for_theme() – Return the default selector for the theme’s background image
    • bw_ret() – Use bw_ret() to return the contents of $bwecho, leaving the global value as NULL
    • bw_trace2() – Trace $value to the trace log file if tracing is active
    • etag() – Output an end tag
    • kv() – Create a keyword value pair
    • stag() – Output an HTML opening tag

    Call hooks

    Function name: bw_background
    Plugin ref: oik-css
    Version: 2.3.1
    Sourcefile: shortcodes/oik-background.php
    File ref: shortcodes/oik-background.php
    API type: shortcode
    Deprecated?: No
    API Letters: B

    Published: August 8, 2014 | Last updated: December 18, 2017

    Information

    Function name: bw_background
    Plugin ref: oik-css
    Version: 2.3.1
    Sourcefile: shortcodes/oik-background.php
    File ref: shortcodes/oik-background.php
    API type: shortcode
    Deprecated?: No
    API Letters: B

    Recent plugin updates

    oik-weight-zone-shipping v0.2.13 oik-weight-zone-shipping v0.2.13 has been tested with WooCommerce 10.1.2 and WordPress 6.8.2 ...
    SB Children Block v1.3.0 Upgrade to SB Children Block v1.3.0 for support for PHP 8.3 and PHP 8.4  ...
    oik v4.15.3 Update to oik v4.15.3 for a couple of security fixes. Tested with WordPress 6.8.2 ...
    oik-privacy-policy v1.4.9 Update to oik-privacy-policy v1.4.9 for a security fix. Tested with WordPress 6.8.2 and PHP 8.3 and PHP 8.4 ...
    oik-nivo-slider v1.17.0 oik-nivo-slider v1.17.0 introduces the Nivo slider block - oik-nivo-slider/nivo. ...

    Plugins

    • All Plugins
    • oik base plugin
    • FREE oik plugins
    • WordPress plugins
    • Premium oik plugins

    Themes

    • FREE themes
    • Bespoke themes
    • Premium themes

    Blocks

    • All Blocks
    • Block examples
    • About Blocks

    Shortcodes

    • All Shortcodes
    • Shortcode examples
    • About Shortcodes

    Reference

    • About APIs
    • All APIs
    • All Classes
    • All Files
    • All Hooks

    Support

    • Contact
    • Cookies policy
    • Get API key
    • Privacy
    • Request support
    • Sitemap
    • Stay informed
    • Terms and Conditions
    oik-plugins
    Email: herb@bobbingwide.com

    Weight shipping plugins

    Find out which cart weight shipping plugin you need for your WooCommerce site.
    Which cart weight based plugin do I need?

    Site:  www.oik-plugins.com
    © Copyright oik-plugins 2011-2025. All rights reserved.


    Website designed and developed by Herb Miller of Bobbing Wide
    Proudly powered by WordPress and oik-plugins

    WordPress version: 6.8.3

    Gutenberg version: 21.7.0

    PHP version: 8.2.29