例如,将PDF附件ID添加为自定义字段值attached_pdf_id
.
使用获取URLwp_get_attachment_url()
:
<?php
if ( is_user_logged_in() ) {
$pdf_link = wp_get_attachment_url( get_post_meta( get_the_ID(), \'attached_pdf_id\', true ) );
if ( $pdf_link ) {
?><a href = "<?php echo $pdf_link ?>" >Download</a><?php
} else {
?>Sorry, no link available. Please contact the webmaser.<?php
}
}
?>