如何将wordpress文章缩略图的调用方法

在学建网站过程中,许多时分需求在网站上显现文章的缩略图,这样能够让整个网站不是太单调就运用了缩略图。

如何将wordpress文章缩略图的调用方法

我们自己做网站时,如安在自己网站上调用文章缩略图呢?下面来讲一下文章缩略图调用办法。

办法/过程

  1. 在自己的wordpress模板中找到模板函数文件functions.php;如何将wordpress文章缩略图的调用方法
  2. 在functions.php张贴下面的缩略图代码:
    //调用缩略图
    function get_first_image() {
    global $post;
    $first_img = '';
    ob_start();
    ob_end_clean();
    $output = preg_match_all('/<img.+src=[ ??].*="" ??]+)[="" ??]([^="">/i', $post->post_content, $matches);
    $first_img = $matches [1] [0];
    if(empty($first_img)){ //Defines a default image
    $first_img = bloginfo('template_url') . "/images/default.jpg";
    };
    return $first_img;
    }</img.+src=[>
  3. 在网站模板的恣意一个模板中,只需需显现缩略图片方位,运用下面的调用代码来调用缩略图。
    trim(strip_tags( $post->post_title ))));} else {?>
  4. 上面代码里的29,296为图片的尺度,能够依据自己网站的需求进行修正。

经过上面的办法,我们自己建网站时,也能够很轻松的调用文章缩略图片了。

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: