Monday, 15 March 2010

Content block shortcode plugin for Wordpress 3.9.x theme -



Content block shortcode plugin for Wordpress 3.9.x theme -

i developing custom shortcode wordpress 3.9.x plugin code doesn't work properly. code should alter based on parameter media="image" or media="video" , css class should add together based on parameter position="left" or position="right".

if image, value path image url. if, video, value path youtube embed code url.

any help?

shortcodes below:

[contentblock class="gray" position="left" media="video" path="....youtube video link...."]video[/contentblock] [contentblock class="gray" position="left" media="image" path="....image url...." alt="alter text" ]image[/contentblock]

code below:

function contentposfun( $atts, $content = null ) { extract( shortcode_atts( array( "class" => '', "path" => '', "alt" => '', "contentpos" => '', //left, right "contentleft" => '', "mediaright" => '', "mediatype" => '', // image, video "isimage" => '', "isvideo" => '', "imgcenter" => '', ), $atts, 'contentblock' ) ); if($contentpos == "left"){ $mediaright = " col-md-push-7 "; $contentleft = " col-md-upll-5 "; } else { $mediaright = " "; $contentleft = " "; } if($mediatype == "image"){ $imgcenter = ' img_center'; $mediatype .= ' <img src="' .$path. '" alt="'.$alt.'" class="img-responsive"' . ' />'; } else { $mediatype .= ' <div class="flex-video widescreen"><iframe width="560" height="315" src="' .$path. '" frameborder="0" allowfullscreen></iframe></div>'; } homecoming '<div class="container-fluid '.$class.'"> <div class="row"> <div class="container full_height"> <div class="row full_height relative"> <div class="col-md-5' .$imgcenter. '' .$mediaright.'">' .$mediatype. '</div> <div class="col-md-7'.$contentleft.'full_height absolute "> <div class="table full_height"> <div class="table-row full_height"> <div class="table-cell full_height valign_middle">' .do_shortcode($content). '</div> </div> </div> </div> </div> </div> </div> </div>'; } add_shortcode( 'contentblock', 'contentposfun' );

the shortcode attributes used in actual shortcode , ones have used in function different. attribute names should same in order work.

following sample code :

// add together shortcode function video_embed_shortcode( $atts, $content = "" ) { // attributes extract( shortcode_atts( array( 'src' => '', 'width' => '', 'height' => '', ), $atts ) ); // code homecoming '<embed src="' . $src . '" width="' . $width . '" height="' . $height . '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true">' . $content; } add_shortcode( 'video_embed', 'video_embed_shortcode' );

shortcode above :

[video_embed src="" width="" height=""]content[/video_embed]

wordpress shortcode

No comments:

Post a Comment