1

下面的这个 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>';
}
4

2 回答 2

0

这就是我在下面的回复中的意思。

array(  
'post_type' => 'attachment',  
'post_mime_type'=>'image',  
'numberposts' => 1,  
'post_status' => null,  
'post_parent' => $post->ID ,
'target' => 'target="_blank"'; 
)

看看它是否以这种方式工作。

于 2013-03-16T04:02:26.330 回答
0

amek teh chages 试试这个

 foreach ( $attachments as $attachment ) {
echo '<a href="javascript:void(0);"
    onclick="document.execCommand(\'SaveAs\', true, \'' . get_permalink( $attachment->ID ) . '\');" target="blank">
    Download This Wallpaper</a>';

}

希望这会对你有所帮助

于 2013-03-16T04:20:18.157 回答