QQ咨询不加好友发不了信息,咨询前先加好友! → QQ:820896380 ×

wordpress文章缩略图的调用方法

很多时候需要在网站上显示文章的缩略图,这样可以让整个网站不是太单调。就是学做网站论坛的“学员网站制作案例”版块,就使用了缩略图。

wordpress文章缩略图的调用方法

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

方法/步骤 在自己的wordpress模板中找到模板函数文件functions.php;wordpress文章缩略图的调用方法n 在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&#8217😉 . “/images/default.jpg”; }; return $first_img; } 在网站模板的任意一个模板中,只要需显示缩略图片位置,使用下面的调用代码来调用缩略图。 <?php if ( has_post_thumbnail() ) { the_post_thumbnail(array(296,296),array(‘alt’=> trim(strip_tags( $post->post_title ))));} else {?><img src=”<?php echo get_first_image(); ?>” alt=”<?php the_title(); ?>” width=”296px” height=”296px”/><?php }?> 上面代码里的29,296为图片的尺寸,可以根据自己网站的需要进行修改。 通过上面的方法,我们自己建网站时,也可以很轻松的调用文章缩略图片了。

给TA打赏
共{{data.count}}人
人已打赏
wordpress教程

增加WordPress Related Posts日志插件自动缩略图功能

2023-2-16 15:45:05

wordpress教程

WordPress分类目录页面获取当前分类的ID及判断是否为子分类目录的方法

2023-2-16 15:45:16

个人中心
购物车
优惠劵
有新私信 私信列表
搜索