我正在開發自定義的短代碼wordpress 3.9.x插件,但代碼無法正常工作。代碼應根據media =「image」或media =「video」等參數進行更改,並且應根據參數position =「left」或position =「right」添加css類。內容塊爲WordPress的3.9.x主題shortcode插件
如果圖片,路徑的值將是圖片url。 如果視頻,路徑的值將被YouTube嵌入代碼網址。
任何幫助?
短代碼是如下:
[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]
守則如下:
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>';
}
return '<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');
WordPress的9.x中?你是否偶然擁有DeLorean? – APAD1
Wordpress 9.x是錯字。 – Atul