在WordPress的single.php中显示附件URL

在WordPress的single.php中显示附件URL,wordpress,Wordpress,我一直在尝试获取附件URL,到目前为止,这段代码获得了图像的直接链接 <?php if ( $attachments = get_children( array( 'post_type' => 'attachment', 'post_mime_type'=>'image', 'numberposts' => 1, 'post_status' => null, 'post_parent' => $post->ID

我一直在尝试获取附件URL,到目前为止,这段代码获得了图像的直接链接

<?php if ( $attachments = get_children( array(
    'post_type' => 'attachment',
'post_mime_type'=>'image',
    'numberposts' => 1,
    'post_status' => null,
    'post_parent' => $post->ID
     )));
    foreach ($attachments as $attachment) {
    echo '<a target="_blank" href="' . wp_get_attachment_url( $attachment->ID )  . '">Download Full Size</a>';
 }

 ?>


但是我想要的是附件URL,请帮助…

我认为你做得不对,你把上传文件的URL存储在数据库中了吗? 如果没有,那么你不能

使用自定义字段来存储和使用它们

如果你不想编码就使用这个插件,你只需要使用而不是wp\u get\u attachement\u url