欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

WordPress D8 主题当中截取文章首图并显示的函数

程序员文章站 2022-04-28 19:18:47
...

取自 WordPress D8 主题;

路径 theme\d8\modules ;

  1. if ( ! function_exists( 'deel_thumbnail' ) ) :
  2. function deel_thumbnail() {
  3. global $post;
  4. if ( has_post_thumbnail() ) {
  5. $domsxe = simplexml_load_string(get_the_post_thumbnail());
  6. $thumbnailsrc = $domsxe->attributes()->src;
  7. echo 'WordPress D8 主题当中截取文章首图并显示的函数';
  8. } else {
  9. $content = $post->post_content;
  10. preg_match_all('//sim', $content, $strResult, PREG_PATTERN_ORDER);
  11. $n = count($strResult[1]);
  12. if($n > 0){
  13. echo 'WordPress D8 主题当中截取文章首图并显示的函数';
  14. }else {
  15. echo 'WordPress D8 主题当中截取文章首图并显示的函数';
  16. }
  17. }
  18. }
  19. endif;
复制代码