下面这段代码可以将链接到文章的图片附件自动显示在文章中,不需要你手工编辑。
将代码添加到你的主题functions.php文件中:
- usp_display_images() {
- ;
- = (\’order\’=>\’ASC\’, \’post_type\’=>\’attachment\’, \’post_parent\’=>->ID, \’post_mime_type\’=>\’image\’, \’post_status\’=>null);
- = get_posts(); ?>
- <div =>
- <?php ( ) {
- = wp_get_attachment_image_src(->ID, \’medium\’);
- = wp_get_attachment_image_src(->ID, \’full\’); ?>
- <a href= target=><img src= width= height= alt=></a>
- <?php }
- = get_post_meta(->ID, \’user_submit_name\’, true);
- = get_post_meta(->ID, \’user_submit_url\’, true);
- (filter_var(, FILTER_VALIDATE_URL) !== false) {
- \'<span =>Posted by <a href=>\’ . . \'</a></span> \’;
- } ?>
- </div>
- <?php }
- add_filter(\’the_content\’, \’usp_display_images\’);
当然,还需另外的CSS样式及HTML代码配合图片显示。
原文:http://wp-mix.com/display-images-attached-post/
暂无评论内容