我正在尝试将媒体中的所有图片插入页面。意思是所有的图片,博客中添加的所有内容。我整天都在看这个功能。有没有什么捷径或简单的方法?
提前谢谢。
我正在尝试将媒体中的所有图片插入页面。意思是所有的图片,博客中添加的所有内容。我整天都在看这个功能。有没有什么捷径或简单的方法?
提前谢谢。
首先,你需要create a custom page Template, 保存自定义循环输出。创建一个主题文件,名为。template-all-images.php
, 标题如下:
<?php
/**
* Template name: All Images
*/
?>
然后,在自定义页面模板中,需要查询所有图像附件。尝试使用WP_Query()
, with post type/status arguments:<?php
$images_query_args = array(
\'post_type\' => \'attachment\',
\'post_status\' => \'inherit\',
\'post_mime_type\' => \'image\'
);
$images_query = new WP_Query( $images_query_args );
?>
然后,输出查询:<?php
if ( $images_query->have_posts() ) : while ( $images_query->have_posts() ) : $images_query->the_post();
// Normal loop output goes here
endwhile; endif;
// Be kind; rewind
wp_reset_postdata();
?>
对于循环输出,如果您只想输出完全成形的图像,可以使用。wp_get_attachment_image()
:<?php
wp_get_attachment_image( get_the_ID(), \'large\' );
?>
(更换\'large\'
使用所需的图像大小,或忽略以使用默认大小,\'thumbnail\'
.)整个自定义页面模板文件可能如下所示:
<?php
/**
* Template name: All Images
*/
// Get the header
get_header();
// Image attachment query arguments
$images_query_args = array(
\'post_type\' => \'attachment\',
\'post_status\' => \'inherit\',
\'post_mime_type\' => \'image\'
);
// Query image attachments
$images_query = new WP_Query( $images_query_args );
// Image attachment query loop
if ( $images_query->have_posts() ) : while ( $images_query->have_posts() ) : $images_query->the_post();
// Output the attachment image
wp_get_attachment_image( get_the_ID(), \'large\' );
endwhile; endif;
// Be kind; rewind
wp_reset_postdata();
// Get the footer
get_footer();
?>
使用自定义页面模板确保template-all-images.php
已保存到Theme directory 在下面wp-content/themes/{theme-name}
.今天早上我wordpress博客上的大部分图片(http://records.photodharma.net)已停止加载。这甚至发生在嵌入式系统上。此处嵌入的所有图像:http://records.photodharma.net/photos/chiang-mai-photo-albums-of-modern-structures 当我在Firebug中查看它们时,它们会出现,但不会出现在页面上。有几次我看到图像加载后不久就消失了,所以它们似乎试图加载,但被阻止了。我做了一些搜索,并尝试了各种方法,如更新