下面的这个 php 将像这样打印http://example.com/wp-content/uploads/2013/01/imagename.jpg带有锚文本“下载”
<?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 wp_get_attachment_link( $attachment->ID, '' , false, true, 'Download');
}
?>
1.当用户点击此链接时,如何在_blank中定位或在新标签中打开。
2.这个短代码是否可以结合Javascript来制作强制下载链接?看起来像波纹管。
if ( $attachments = get_posts( array(
'post_type' => 'attachment',
'post_mime_type'=>'image',
'numberposts' => -1,
'post_status' => 'any',
'post_parent' => $post->ID,
) ) );
foreach ( $attachments as $attachment ) {
echo '<a href="javascript:void(0);"
onclick="document.execCommand(\'SaveAs\', true, \'' . get_permalink( $attachment->ID ) . '\');">
Download This Wallpaper</a>';
}