解决关于如何将图像与文本(内容)分离的第一个更具体的问题。像往常一样,有很多方法可以达到这样的结果。我用这个:
如您所知,您可以为每篇文章添加图片。您肯定会遇到的问题是如何在不使用内容中的图库占位符的情况下将特定照片附加到特定帖子(WYSISYG 编辑器)。
您可以通过“添加媒体”按钮上传照片来做到这一点。必须将这些图像“上传”到帖子中,而不是从媒体库中选择它们。据我了解,如果没有插件,这是将图像真正附加到帖子的唯一方法。
问题出现了如何在模板中获取附件。
我使用我编写的这个通用函数functions.php
来获取帖子的附件:
function get_attachment($args) {
$defaults = array( 'post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' =>'any', 'post_parent' => $post->ID);
$options = array_merge($defaults, $args);
return get_posts( $options );
}
由于您可以上传其他类型的媒体(视频、音频),因此有一些示例如何在模板中使用上述功能:
$gallery_images = get_attachment(array('post_parent' => $post->ID, 'post_mime_type' => 'image'));
$audio_files = get_attachment(array('post_parent' => $post->ID, 'post_mime_type' => 'audio'));
$video_files = get_attachment(array('post_parent' => $post->ID, 'post_mime_type' => 'video'));
为了回答您更通用的问题——将内容与内容分开——实际上,您可以通过创建自定义字段或元框来更改“添加帖子表单”的管理界面。
创建元框的帮助可以在 Wordpress Codex 中找到,例如这里:
http ://codex.wordpress.org/Function_Reference/add_meta_box
我希望它有点启发。