Heim >Backend-Entwicklung >PHP-Tutorial >WordPress D8 主题当中截取文章首图并显示的函数

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-25 09:13:041216Durchsuche

取自 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('/WordPress D8 主题当中截取文章首图并显示的函数 /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;
复制代码



Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn