当前位置: 五行网-我行网 > wordpress, 建站编程 >正文

自动显示 WordPress 缩略图的方法,很多主题也只是通过利用 WordPress 中的自定义字段(custom field)功能来获取缩略图。但是,这种方法相当不自动,每次都得复制一遍缩略图地址,不是我们鱼类思维。大家知道,每当我们利用 WordPress 后台上传图片时,WordPress 都会自动为我们创建一个缩略图,那么,我们是否可以自动获取这个缩略图呢?答案是肯定的。下面我们一起来看看这篇 WordPress 教程吧

sofish 小盆友在他的博客中提到一直没有找到自动显示 WordPress 缩略图的方法,很多主题也只是通过利用 WordPress 中的自定义字段(custom field)功能来获取缩略图。但是,这种方法相当不自动,每次都得复制一遍缩略图地址,不是我们鱼类思维。大家知道,每当我们利用 WordPress 后台上传图片时,WordPress 都会自动为我们创建一个缩略图,那么,我们是否可以自动获取这个缩略图呢?答案是肯定的。下面我们一起来看看这篇 WordPress 教程吧

新代码可实现的功能

  1. Hyperlinks
  2. 图片链接到文章地址

  3. Thickbox
  4. 实现 Thickbox 图片缩放效果

  5. 图片分类

首先,我们将以下代码复制到你主题的 functions.php 中
Code:
Download the post image code here
以上代码会自动列出 WordPress 文章中的所有附件图片,并显示第一张图片的缩略图。

使用方法:

将以下代码插入你想放置的地方,比如:日志post_content()前面


1
2
3
<?php the_image(size, class , link to post , link using thickbox, echo result); ?>
//in the example video the single post page uses:
<?php the_image('medium','post-image',false,true); ?>

函数默认值:

  • Size — medium
  • Class — blank
  • link to post — false
  • link using thickbox — false
  • echo result — true

本站实例:<div><a href=”<?php the_permalink(); ?>” title=”<?php the_title();?>” >
<?php the_image(’medium’,’thumb_image’,true,false); ?>
</a></div>
<div>
<p><?php echo mb_strimwidth(strip_tags(apply_filters(’the_content’, $post->post_content)), 0, 290,”…”); ?></p>
</div>

本文译自:Post image the easy peasy way
中文翻译:自动获取 WordPress 缩略图
转载于http://eachsite.org

   

Leave a Reply