显示所有链接到文章的图片附件

下面这段代码可以将链接到文章的图片附件自动显示在文章中,不需要你手工编辑。

将代码添加到你的主题functions.php文件中:

  1.   
  2.  usp_display_images() {  
  3.       ;  
  4.       = (\’order\’=>\’ASC\’, \’post_type\’=>\’attachment\’, \’post_parent\’=>->ID, \’post_mime_type\’=>\’image\’, \’post_status\’=>null);  
  5.       = get_posts(); ?>  
  6.    
  7.           <div =>  
  8.           <?php  (  ) {  
  9.                 = wp_get_attachment_image_src(->ID, \’medium\’);  
  10.                 = wp_get_attachment_image_src(->ID, \’full\’); ?>  
  11.                <a href= target=><img src= width= height= alt=></a>  
  12.           <?php }  
  13.                 = get_post_meta(->ID, \’user_submit_name\’, true);  
  14.                 = get_post_meta(->ID, \’user_submit_url\’, true);  
  15.                 (filter_var(, FILTER_VALIDATE_URL) !== false) {  
  16.                 \'<span =>Posted by <a href=>\’ .  . \'</a></span> \’;  
  17.           } ?>  
  18.           </div>  
  19.    
  20. <?php }  
  21. add_filter(\’the_content\’, \’usp_display_images\’);  

当然,还需另外的CSS样式及HTML代码配合图片显示。

原文:http://wp-mix.com/display-images-attached-post/

    © 版权声明
    THE END
    喜欢就支持一下吧
    点赞0 分享
    评论 抢沙发

    请登录后发表评论

      暂无评论内容