当前位置:Gxlcms > PHP教程 > WordPressD8主题当中截取文章首图并显示的函数

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

时间:2021-07-01 10:21:17 帮助过:3人阅读

取自 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 ''.trim(strip_tags( $post->post_title )).'';
  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 ''.trim(strip_tags( $post->post_title )).'';
  14. }else {
  15. echo ''.trim(strip_tags( $post->post_title )).'';
  16. }
  17. }
  18. }
  19. endif;

人气教程排行