我正在使用WordPress的“附件”功能,以允许我的主题的最终用户上传将出现在帖子内容上方的图像(而不是插入帖子本身)。
我唯一的问题是,没有一个字段,以允许最终用户指定链接,应加载时,最终用户点击附加的图像之一。我想将此字段添加到帖子附件编辑器(列出帖子附件中的“图库”)。
或者,也许另外,我希望能够在通过媒体管理器列表查看图像时执行相同的操作。
目前,我使用"description“字段来存储图像的超链接。并像这样检索它(工作得很好,但描述不是链接目的地的语义):
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;
}
}发布于 2010-10-22 01:01:28
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); https://stackoverflow.com/questions/3969444
复制相似问题