QQ咨询不加好友发不了信息,咨询前先加好友! → QQ:820896380 ×

WordPress链接到文章的图片附件自动显示在文章中

WordPress 下面这段代码可以将链接到文章的图片附件自动显示在文章中,不需要你手工编辑。 将代码添加到你的主题functions.php文件中: // display user-submitted images function usp_display_images() { global $post; $args...
Wordpress链接到文章的图片附件自动显示在文章中
WordPress

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

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

// display user-submitted images  
function usp_display_images() {  
     global $post;  
     $args = array('order'=>'ASC', 'post_type'=>'attachment', 'post_parent'=>$post->ID, 'post_mime_type'=>'image', 'post_status'=>null);  
     $items = get_posts($args); ?>  
          <div class="usp-image">  
          <?php foreach ($items as $item) {  
               $atts = wp_get_attachment_image_src($item->ID, 'medium');  
               $full = wp_get_attachment_image_src($item->ID, 'full'); ?>  
               <a href="<?php%20echo%20$full[0];%20?>" target="_blank"><img src="<?php%20echo%20$atts[0];%20?>" width="<?php echo $atts[1]; ?>" height="<?php echo $atts[2]; ?>" alt=""></a>  
          <?php }  
               $author = get_post_meta($post->ID, 'user_submit_name', true);  
               $url = get_post_meta($post->ID, 'user_submit_url', true);  
               if (filter_var($url, FILTER_VALIDATE_URL) !== false) {  
               echo '<span class="usp-author-link">Posted by <a href="'%20.%20$url%20.%20'">' . $author . '</a></span> ';  
          } ?>  
          </div>  
<?php }  
add_filter('the_content', 'usp_display_images');  

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

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA打赏
共{{data.count}}人
人已打赏
wordpress教程

WordPress简单的网页跳转代码

2023-2-16 23:48:53

wordpress教程

WordPress Smartideo插件如何将B站BV号链接转av号

2023-2-16 23:48:55

!
你也想出现在这里?立即 联系我们吧!
信息
个人中心
购物车
优惠劵
有新私信 私信列表
搜索