首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在WordPress图片附件编辑器中添加"Link Destination“字段?

如何在WordPress图片附件编辑器中添加"Link Destination“字段?
EN

Stack Overflow用户
提问于 2010-10-19 22:33:06
回答 1查看 233关注 0票数 0

我正在使用WordPress的“附件”功能,以允许我的主题的最终用户上传将出现在帖子内容上方的图像(而不是插入帖子本身)。

我唯一的问题是,没有一个字段,以允许最终用户指定链接,应加载时,最终用户点击附加的图像之一。我想将此字段添加到帖子附件编辑器(列出帖子附件中的“图库”)。

或者,也许另外,我希望能够在通过媒体管理器列表查看图像时执行相同的操作。

目前,我使用"description“字段来存储图像的超链接。并像这样检索它(工作得很好,但描述不是链接目的地的语义):

代码语言:javascript
复制
if ($images = get_children(array('post_parent' => get_the_ID(),'post_type' => 'attachment','post_mime_type' => 'image', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC'    )))
    {
    foreach( $images as $image ) :
        echo "<a href='".$image->post_content."'><img src='".wp_get_attachment_url($image->ID, 'medium')."' /></a>";
    endforeach;
    }   
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-10-22 01:01:28

代码语言:javascript
复制
function my_image_attachment_fields_to_edit($form_fields, $post) {  
    $form_fields["custom1"] = array(  
        "label" => __("Image Links To"),  
        "input" => "text", // this is default if "input" is omitted  
        "value" => get_post_meta($post->ID, "_custom1", true)  
    );    
    return $form_fields;  
}  

function my_image_attachment_fields_to_save($post, $attachment) {  
    if( isset($attachment['custom1']) ){  
        update_post_meta($post['ID'], '_custom1', $attachment['custom1']);  
    }  
    return $post;  
} 

add_filter("attachment_fields_to_edit", "my_image_attachment_fields_to_edit", null, 2); 
add_filter("attachment_fields_to_save", "my_image_attachment_fields_to_save", null, 2); 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3969444

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档