将视频上传器添加到我的Wordpress Customiser

时间:2017-10-10 03:50:01

标签: wordpress video wordpress-theming

努力为我的wordpress主题添加视频上传器,有人可以帮忙吗?

我在functions.php文件中有这个:

        // Andys Video Section

    $wp_customize->add_section("Videosection", array(
        "title" => __("Video Section", "customizer_ads_sections"),
        "priority" => 20,
    ));
$wp_customize->add_setting( 'video_upload',
   array(
      'default' => '',
      'transport' => 'refresh',
      'sanitize_callback' => 'absint',
             'type' => 'theme_mod',
   )
);

$wp_customize->add_control( new WP_Customize_Media_Control( $wp_customize, 'video_upload',
   array(
      'label' => __( 'Default Media Control' ),
      'description' => esc_html__( 'This is the description for the Media Control' ),
      'section' => 'Videosection',
      'mime_type' => 'video',  // Required. Can be image, audio, video, application, text
      'button_labels' => array( // Optional
         'select' => __( 'Select File' ),
         'change' => __( 'Change File' ),
         'default' => __( 'Default' ),
         'remove' => __( 'Remove' ),
         'placeholder' => __( 'No file selected' ),
         'frame_title' => __( 'Select File' ),
         'frame_button' => __( 'Choose File' ),

      )
   )
) );

这在我的页面模板上:

<div class="video-container">
         <button style="position:absolute; top:50%; left:50%;" onclick="playPause(); return false;">Click to start</button>

             <video loop controls poster="http://test.guerrilla.nz/wp-content/themes/advocate/images/David_Buckingham.jpg">
<?php echo get_theme_mod( 'video_upload' ) ?>
        <source src="<?php echo get_theme_mod( 'video_upload' ) ?>" width="100" type="video/mp4">
          <source src="<?php echo get_theme_mod( 'video_upload' ) ?>" type="video/ogg">
          <source src="<?php echo get_theme_mod( 'video_upload' ) ?>" type="video/ogg">
          Your browser does not support the video tag.
    </video>
        </div>

但视频无法上传,有人可以提供帮助吗?

3 个答案:

答案 0 :(得分:0)

这是完整的功能:

function andys_theme_customizer( $wp_customize ) {



        // Andys Video Section

    $wp_customize->add_section("Videosection", array(
        "title" => __("Video Section", "customizer_ads_sections"),
        "priority" => 20,
    ));

$wp_customize->add_setting( 'video_upload',
   array(
      'default' => '',
      'transport' => 'refresh',
      'sanitize_callback' => 'absint',
             'type' => 'theme_mod',
   )
);

$wp_customize->add_control( new WP_Customize_Media_Control( $wp_customize, 'video_upload',
   array(
      'label' => __( 'Default Media Control' ),
      'description' => esc_html__( 'This is the description for the Media Control' ),
      'section' => 'Videosection',
      'mime_type' => 'video',  // Required. Can be image, audio, video, application, text
      'button_labels' => array( // Optional
         'select' => __( 'Select File' ),
         'change' => __( 'Change File' ),
         'default' => __( 'Default' ),
         'remove' => __( 'Remove' ),
         'placeholder' => __( 'No file selected' ),
         'frame_title' => __( 'Select File' ),
         'frame_button' => __( 'Choose File' ),

      )
   )
) );



}

add_action( 'customize_register', 'andys_theme_customizer' );

答案 1 :(得分:0)

谢谢,好的,请尝试将模板中的代码更改为:

<div class="video-container">
<?php
$id = get_theme_mod('video_upload');

$attr = array(
    'src' => wp_get_attachment_url($id)
);

echo wp_video_shortcode( $attr );
?>
</div>

查看文档wp_video_shortcode

答案 2 :(得分:0)

遇到同样的问题:我的视频的 src="" 只插入了一个整数。 解决方案是将“wp_get_attachment_url()”放在“get_theme_mod()”周围。

所以它必须是:port id="1" 作为源。然后将插入正确的网址而不是其 ID。