我是一个编码初学者,我正在使用翻译器提问。我请求你的谅解。
我使用的是fancybox 3.5.7版本。
我使用";jquery.fancybox.min.js";让YouTube问世。
然而,如果JS的调用速度有问题,请在加载JS之前单击以转到YouTube网站。
为了解决这个问题,我将js代码作为脚本放在header.php文件中。问题比以前少了,但问题是间歇性发生的。
有没有办法不去YouTube网站,即使我在加载fancybox js之前点击了它?
谢谢。请给我一个提示,我可以试试。
这是一个代码。
函数.php
add_action( "wp_enqueue_scripts", "include_custom_style" );
function include_custom_style(){
wp_enqueue_style( "fancybox-css", get_stylesheet_directory_uri() . "/css/jquery.fancybox.min.css");
wp_enqueue_script( "fancybox-js", get_stylesheet_directory_uri() . "/js/jquery.fancybox.min.js");
博客列表.php
function blackvue_blog_list() {
global $content;
ob_start();
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
'post_type' => 'post',
'paged' => $paged,
'post_status' => 'publish',
'order' => 'DESC'
);
$loop = new WP_Query( $args );
?>
<div class="elementor-posts blog-archive">
<?php
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
$postID = get_the_ID();
$content = get_the_content();
$videourl = get_the_post_video_url( $postID );
$video_id = explode("?v=", $videourl);
$video_id = $video_id[1];
$imgyoutube = 'http://img.youtube.com/vi/'.$video_id.'/0.jpg';
$thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
?>
<div class="news-post elementor-post elementor-grid-item">
<div class="elementor-post__thumbnail__link" style="background-image: url(<?php echo $thumb[0];?>);">
<?php if(!empty($videourl)){
echo '<a data-fancybox href="'.$videourl.'">
<img alt="'.get_the_title().'" src="'.$thumb[0].'" class="elementor-post__thumbnail"/>
<div class="vdo">
<i class="fa fa-youtube-play" aria-hidden="true"></i>
</div>
</a>';
}elseif(has_post_thumbnail()){
$permlink = get_the_permalink();
echo '<a href="'.$permlink.'"><img alt="'.get_the_title().'" src="'.$thumb[0].'" class="elementor-post__thumbnail"/></a>';
}
else{
}?>
</div>
最简单的解决方案是将href="URL"
属性更改为data-src="URL"