如果您将permalink更改为在设置中发布名称并附上证词。pdf在您的帖子中,您将获得http://example.com/your_post/testimony.pdf, 要获取您可以使用此代码获取的文本的url,请执行以下操作
<?php
$args = array(
\'post_type\' => \'attachment\',
\'numberposts\' => -1,
\'post_status\' => \'any\',
\'post_parent\' => $post->ID,
\'exclude\' => get_post_thumbnail_id(),
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo apply_filters( \'the_title\', $attachment->post_title );
the_attachment_link( $attachment->ID, false );
}
}
?>
或者将此代码放在单个中。php
<ul>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
//add in bootom of loops
$args = array(
\'post_type\' => \'attachment\',
\'numberposts\' => -1,
\'post_status\' => null,
\'post_parent\' => $post->ID
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo \'<li>\';
the_attachment_link( $attachment->ID, true );
echo \'<p>\';
echo apply_filters( \'the_title\', $attachment->post_title );
echo \'</p></li>\';
}
}
endwhile; endif; ?>
</ul>
代码返回
http://wp.example.net/post_name/attachment_name.这是参考
https://codex.wordpress.org/Function_Reference/get_attachment_link