douzhang6176 2013-09-25 00:11
浏览 41
已采纳

Word中的PHP函数不显示嵌入的YouTube视频

The php code is working and is displaying contact forms and galleries, however, the youtube video links are not embeding like they would in a normal Wordpress page. It just displays the address in the popup window. This was working when using html code on the page, but does not work once inside a PHP function. Here's the code if anyone can help with it. Thanks.

function artistArea($atts, $content = null) {
   extract(shortcode_atts(array('number' => '#', 'photo' => '#', 'name' => '#', 'video' => '#', 'audio' => '#', 'gallery' => '#', 'bio' => '#', 'element1' => '#','element2' => '#','element3' => '#','element4' => '#'), $atts));  

    switch ($number) {
        case '1' :
            $element1 = '1';
            $element2 = '2';
            $element3 = '3';
            $element4 = '4';
            break;
        case '2' :
            $element1 = '5';
            $element2 = '6';
            $element3 = '7';
            $element4 = '8';
            break;
        case '3' :
            $element1 = '9';
            $element2 = '10';
            $element3 = '11';
            $element4 = '12';
            break;
        case '4' :
            $element1 = '13';
            $element2 = '14';
            $element3 = '15';
            $element4 = '16';
            break;
        case '5' :
            $element1 = '17';
            $element2 = '18';
            $element3 = '19';
            $element4 = '20';
            break;
        default :
            $element1 = '1';
            $element2 = '2';
            $element3 = '3';
            $element4 = '2';
            break;
        break;
    }

        switch ($type) {
        case 'lounge' :
            $formType = '[contact-form-7 id="4" title="Lounge Artists"]';
            break;
        case 'magic' :
            $formType = '[contact-form-7 id="184" title="Magic Artists"]';
            break;
        case 'tribute' :
            $formType = '[contact-form-7 id="185" title="Tribute Artists"]';
            break;
        case 'comedy' :
            $formType = '[contact-form-7 id="186" title="Comedy Artists"]';
            break;
        case 'dance' :
            $formType = '[contact-form-7 id="187" title="Dance Artists"]';
            break;
        case 'hen' :
            $formType = '[contact-form-7 id="188" title="Hens Party Artists"]';
            break;
        case 'hypnotist' :
            $formType = '[contact-form-7 id="189" title="Hypnotist Artists"]';
            break;
        case 'circus' :
            $formType = '[contact-form-7 id="190" title="Circus Artists"]';
            break;
        default :
            $formType = '[contact-form-7 id="4" title="Lounge Artists"]';
            break;
        break;
    }

        switch ($audio) {
        case '0' :
            $audioSection = ''; break;
        default :
            $audioSection = '
        <div class="artists_audio">
            <a class="lbp-inline-link-'.$element2.' cboxElement" href="#">AUDIO</a>
            <div style="display: none;"><div id="lbp-inline-href-'.$element2.'" style="padding:10px; background: #fff;">[soundcloud url="'.$audio.'" params="" width=" 100%" height="166" iframe="true" /]</div></div>
        </div>'; break;
        break;
    }

        switch ($video) {
        case '0' :
            $videoSection = ''; break;
        default :
            $videoSection = '       <div class="artists_video">
            <a class="lbp-inline-link-'.$element1.' cboxElement" href="#">VIDEO</a>
            <div style="display: none;"><div id="lbp-inline-href-'.$element1.'" style="padding:10px; background: #fff;">
            '.$video.'
            </div></div>
        </div>'; break;
        break;
    }

        switch ($gallery) {
        case '0' :
            $gallerySection = ''; break;
        default :
            $gallerySection = '                 <div class="artists_pictures">
            <a class="lbp-inline-link-'.$element3.' cboxElement" href="#">PICTURES</a>
            <div style="display: none;"><div id="lbp-inline-href-'.$element3.'" style="padding:10px; background: #fff;">[nggallery id='.$gallery.']</div></div>
        </div>'; break;
        break;
    }   


    $output = '<div class="artist_enclosure">
    <div class="artists_photo">
        <img src="'.$photo.'" alt="'.$name.'" width="150" height="150" class="alignnone size-thumbnail wp-image-39" />
    </div>
    <div class="artists_name"> 
        '.$name.'
    </div>
    <div class="artists_bio">
        '.$content.'
    </div>

    <div class="artists_media">

        '.$videoSection.'

        '.$audioSection.'

        '.$gallerySection.'

        <div class="artists_booknow">
            <a class="lbp-inline-link-'.$element4.' cboxElement" href="#">BOOK NOW!</a>
            <div style="display: none;"><div id="lbp-inline-href-'.$element4.'" style="padding:10px; background: #fff;">'.$formType.'</div></div>
        </div>
    </div>
</div>

        ';
return do_shortcode($output);
}
add_shortcode('artist', 'artistArea');
  • 写回答

1条回答 默认 最新

  • dongwei3151 2013-09-25 02:35
    关注

    do_shortcode doesn't look for oEmbeds. You'll have to call the oEmbed code directly, but there's some setup that needs to be done first before the oEmbed code will look at your content.

    Instead of this…

    return do_shortcode($output);
    

    …you'll need to do something like this:

    // Use the WP_Embed instance WordPress already set up
    global $wp_embed;
    
    /**
     * Replace the global $post with a fake ID (a really crazy one!)
     * or else WP_Embed::autoembed() will skip the oEmbed check
     * for some reason.
     **/
    global $post;
    $oldpost = $post;
    $post = new stdClass();
    $post->ID = PHP_INT_MAX;
    
    // Process oEmbeds
    $output = $wp_embed->autoembed( do_shortcode( $output ) );
    
    // Restore the original $post
    $post = $oldpost;
    
    return $output;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持