很多实用WordPress程序搭建视频站的站长都在吐槽用WordPress做视频方面体验就不是很友好的,为了改进后大大提升了站点的用户体验,需要实现自动提取文章内视频作为封面,今天就分享一下WordPress自动获取文章内视频作为封面的方法。

将下方代码添加进function即可实现:

//提取视频封面

function catch_video_image() {

global $post, $posts;

$video_image = \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’;

ob_start();

ob_end_clean();

$output = preg_match_all(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’/<video.+poster=[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”]([^\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”]+)[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”].*>/i\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, $post->post_content, $matches);

$video_image = $matches [1] [0];

return $video_image;

}

//正则提取字符串中视频url地址

function catch_that_video() {

global $post, $posts;

$first_video = \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’;

ob_start();

ob_end_clean();

$output = preg_match_all(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’/<video[^<>]*src=[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”]([^\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”]+)[\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\”][^<>]*>/im\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, $post->post_content, $matches);

$first_video = $matches [1] [0];

return $first_video;

}

相关新闻

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

联系我们

联系我们

151-1101-0018

在线咨询:
邮件:30115776@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信
关注微信
分享本页
返回顶部