首页 > 新闻资讯 > 显示文件缩略图

显示文件缩略图

3条评论
标签:
更多

这两段代码可以实现显示独立的图片文件或者其他文件的缩略图。首先把第一段代码添加到functions.php中,然后你想在哪块显示就放在哪个模板文件中,想在文章中显示 就放在文章的模板中。
 

function get_attachment_files(){
$args = array(
    'post_type' => 'attachment',
    'numberposts' => -1,
    'post_status' => null,
    'post_parent' => 0
);
$attachments = get_posts($args);
 if ($attachments) {
    foreach ($attachments as $post) {
        setup_postdata($post);
        the_attachment_link($post->ID);
    }
 }
}
 

 

<? get_attachment_files(); ?>

* 版权声明:作者WordPress啦! 转载请注明出处。

#1
也,这个不错哟。很是实用的一个东西哟。我来试一下看呢。
#2
还是没有明白代码的意思。
#3
有用……

发表新评论

此内容将保密,不会被其他人看见。
  • 自动将网址与电子邮件地址转变为链接。
  • 允许HTML标签:<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • 自动断行和分段。

更多关於格式化选项的信息

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.