首页 文章

如何让Wordpress附件适用于媒体库中的现有图像?

提问于
浏览
0

我想在单独的页面上显示每个Wordpress帖子的图像 .

当使用 get_children (或 get_posts )时 'post_type' => 'attachment' 仅在该特定帖子中有效时才有效 .

如果我将现有图像添加到已存在于WP MEDIA LIBRARY中的帖子,则无效 .

无论如何 'attachment' 适用于现有(已上传)的图像?

看我的测试功能:

function echo_first_image($postID){
    $args = array(
        'post_type' => 'attachment',
        'post_parent' => $postID
    );
    $attachments = get_children( $args );
    if($attachments){
        echo'YES';   // test answer
    }else{
        echo'NO';   // test answer
    }
}

编辑:每个'post_type'是一个'附件'有一个'post_parent' - 这是否意味着一个附件只能有一个单亲?

1 回答

  • 0

    目前,在写作时,Wordpress 4.1不包含多父附件,因为数据库关系是一对一的,而不是一对多的 . 您必须找到一个插件,或编写自己的插件来解决这个问题 .

相关问题