使用此附件使目标_Blank PHP

时间:2013-03-16 03:57:32

标签: wordpress media attachment

下面的这个php将打印出这样的http://example.com/wp-content/uploads/2013/01/imagename.jpg锚文本'DOWNLOAD'

<?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结合使用Force下载链接吗?看起来像波纹管。

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>';
}

2 个答案:

答案 0 :(得分:0)

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

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

看看它是否有效。

答案 1 :(得分:0)

进行更改并尝试此操作

 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>';

}

希望这会帮助你