Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 3.9.x主题的内容块短代码插件_Wordpress_Shortcode - Fatal编程技术网

Wordpress 3.9.x主题的内容块短代码插件

Wordpress 3.9.x主题的内容块短代码插件,wordpress,shortcode,Wordpress,Shortcode,我正在开发自定义短代码wordpress 3.9.x插件,但代码不能正常工作。代码应该根据media=“image”或media=“video”等参数进行更改,css类应该根据参数position=“left”或position=“right”进行添加 若为图像,则路径的值将为图像url。 如果是视频,则路径的值将是youtube嵌入代码url 有什么帮助吗 短代码如下所示: [contentblock class="gray" position="left" media="video" pat

我正在开发自定义短代码wordpress 3.9.x插件,但代码不能正常工作。代码应该根据media=“image”或media=“video”等参数进行更改,css类应该根据参数position=“left”或position=“right”进行添加

若为图像,则路径的值将为图像url。 如果是视频,则路径的值将是youtube嵌入代码url

有什么帮助吗

短代码如下所示:

[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' );
代码如下:

[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' );
函数contentposFun($atts,$content=null){
提取(短码)附件(数组)(
“类”=>“”,
“路径”=>“”,
“alt”=>”,
“contentPos”=>“”,//左,右
“contentLeft”=>“”,
“mediaRight”=>“”,
“mediaType”=>“”,//图像,视频
“isImage”=>“”,
“isVideo”=>“”,
“imgCenter”=>“”,
),$atts,'contentblock');
如果($contentPos==“左”){
$mediarright=“col-md-push-7”;
$contentLeft=“col-md-upll-5”;
}
否则{
$mediaRight=“”;
$contentLeft=“”;
}
如果($mediaType==“图像”){
$imgCenter='img_中心';
$mediaType.='';
}
否则{
$mediaType.='';
}
返回'
“.$mediaType。”
'
.do_短代码($content)。
'
';            
}
添加_短代码('contentblock','contentposFun');

在实际短代码中使用的短代码属性与在函数中使用的短代码属性不同。这些属性名称应该相同才能工作

以下是示例代码:

// Add Shortcode
function video_embed_shortcode( $atts, $content = "" ) {

    // Attributes
    extract( shortcode_atts(
        array(
            'src' => '',
            'width' => '',
            'height' => '',
        ), $atts )
    );

    // Code
return '<embed 
        src="' . $src . '"
        width="' . $width . '"
        height="' . $height . '"
        type="application/x-shockwave-flash"
        allowscriptaccess="always"
        allowfullscreen="true">' . $content;

}
add_shortcode( 'video_embed', 'video_embed_shortcode' );
//添加短代码
功能视频\嵌入\短代码($atts,$content=”“){
//属性
提取(短码)(
排列(
“src'=>”,
'宽度'=>'',
'高度'=>'',
),$atts)
);
//代码
返回“”。$content;
}
添加_短码('video_embed'、'video_embed_短码');
上面的短代码如下所示:


[video\u embed src=”“width=”“height=”“]content[/video\u embed]

我的代码已经完成了,并且运行良好。此代码可以生成4种类型的短代码

短代码:

[conblock class="gray" pos="left" media="image" path="img1.png" alt="image text"] Content[/conblock]
[conblock class="white" pos="right" media="image" path="img1.png" alt="image text"] Content[/conblock]
[conblock class="gray" pos="left" media="video" path="//www.youtube.com/embed/A2ojlR2Rxiw"] Content[/conblock]
[conblock class="white" pos="right" media="video" path="//www.youtube.com/embed/A2ojlR2Rxiw"] Content[/conblock]
插件代码:

function conblockFun( $atts, $content = null ) {
    extract( shortcode_atts( array(
        'class' => '', //white, gray
        'pos' => '', //left, right
        'media' => '', //image, video
        'left' => '', // true, false
        'right' => '', //true, false
        'path' => '', // image path or video path          
        'alt' => '', // if image add alt text
    ), $atts, 'conblock' ) );

    $output = '<div class="container-fluid '.$class.'">
                <div class="row">
                <div class="container full_height">
                <div class="row full_height relative">';
    if($pos == 'left' && $media == 'image') { $output .= '<div class="col-md-5 col-md-push-7 img_center"><img src="' .$path. '" alt="'.$alt.'" class="img-responsive"' . ' /></div><div class="col-md-7 col-md-pull-5 full_height absolute">';}
    if($pos == 'left' && $media == 'video') { $output .= '<div class="col-md-5 col-md-push-7"><div class="flex-video widescreen"><iframe width="560" height="315" src="' .$path. '" frameborder="0" allowfullscreen></iframe></div></div><div class="col-md-7 col-md-pull-5 full_height absolute">';}     
    if($pos == 'right' && $media == 'image') { $output .= '<div class="col-md-5 img_center"><img src="' .$path. '" alt="'.$alt.'" class="img-responsive"' . ' /></div><div class="col-md-7 col-md-push-5 full_height absolute">';}
    if($pos == 'right' && $media == 'video') { $output .= '<div class="col-md-5"><div class="flex-video widescreen"><iframe width="560" height="315" src="' .$path. '" frameborder="0" allowfullscreen></iframe></div></div><div class="col-md-7 col-md-push-5 full_height absolute">';} 
    $output .= '<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>
                </div>';
    return $output;
}

add_shortcode("conblock", "conblockFun");
函数conblockFun($atts,$content=null){
提取(短码)附件(数组)(
'class'=>'',//白色、灰色
'pos'=>'',//左,右
'媒体'=>'',//图像,视频
'左'=>'',//对,错
'右'=>'',//对,错
'路径'=>'',//图像路径或视频路径
'alt'=>'',//如果图像添加alt文本
),$atts,'conblock');
$output=
';
如果($pos=='left'&&$media=='image'){$output.='''';}
如果($pos=='left'&&$media=='video'){$output.=''';}
如果($pos=='right'&&$media=='image'){$output.=''';}
如果($pos=='right'&&$media=='video'){$output.='''';}
$output.='
'
.do_短代码($content)。
'
';
返回$output;
}
添加_短代码(“conblock”、“conblockFun”);

Wordpress 9.x?你是不是碰巧拥有一辆德洛林?WordPress9.x是打字错误。