如何添加“链接目标” WordPress 图像附件编辑器中的字段?
我正在使用 WordPress“附件”功能来允许我的主题的最终用户上传将出现在帖子内容上方的图像(而不是插入到帖子本身中)。
我遇到的唯一问题是,没有一个字段允许最终用户指定当最终用户单击所附图像之一时应加载的链接。我想将此字段添加到帖子附件编辑器(列出帖子所附图像的“图库”的编辑器)。
或者,也许此外,我希望能够在通过媒体管理器列表查看图像时执行相同的操作。
目前,我正在使用“描述”字段来存储图像的超链接。并像这样检索它(工作完美,但描述对于链接目的地来说不是语义的):
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;
}
}
I'm using the WordPress "attachment" feature to allow end users of my theme to upload images that will appear above the post content (not inserted into the post itself).
The only problem I have is that there is not a field to allow the end user to specify the link that should be loaded when the end user clicks on one of the attached images. I'd like to add this field to the post attachment editor (the one that lists the "Gallery" of images attached to the post).
Alternately, and perhaps in addition, I'd like to be able to do the same thing when viewing images via the Media manager listing.
Currently, I'm using the "description" field to store the hyperlink to the image. and retrieving it like so (works perfectly but description is not semantic to link destination):
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;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)