WordPress教程

WordPress 自动获取文章内视频作为封面的方法

阿里云

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

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

也想出现在这里?联系我们
创客主机
  1. //提取视频封面
  2.  
  3. function catch_video_image() {
  4.  
  5. global $post, $posts;
  6.  
  7. $video_image = '';
  8.  
  9. ob_start();
  10.  
  11. ob_end_clean();
  12.  
  13. $output = preg_match_all('/<video.+poster=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
  14.  
  15. $video_image = $matches [1] [0];
  16.  
  17. return $video_image;
  18.  
  19. }
  20.  
  21. //正则提取字符串中视频url地址
  22.  
  23. function catch_that_video() {
  24.  
  25. global $post, $posts;
  26.  
  27. $first_video = '';
  28.  
  29. ob_start();
  30.  
  31. ob_end_clean();
  32.  
  33. $output = preg_match_all('/<video[^<>]*src=[\"]([^\"]+)[\"][^<>]*>/im', $post->post_content, $matches);
  34.  
  35. $first_video = $matches [1] [0];
  36.  
  37. return $first_video;
  38.  
  39. }

WordPress 自动获取文章内视频作为封面的方法

已有 114 人购买
查看演示升级 VIP立刻购买

收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!