低於這個PHP將打印這樣http://example.com/wp-content/uploads/2013/01/imagename.jpg的錨文本「下載」使目標_blank隨着這Attacment PHP
<?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.is可能這個短代碼結合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>';
}
解析錯誤: '' 語法錯誤,意外 – 2013-03-16 04:07:10
感謝好友.. :) – 2013-03-16 04:15:08
爲什麼不嘗試爲你的數組包含一個目標? 陣列( 'post_type'=> '附着', 'post_mime_type'=> '圖像', 'numberposts'=> -1, 'post_status'=> '任意', 'post_parent'=> $交 - > ID, 'target'=>'_blank' ) 看看它是否以這種方式工作。 – OmniPotens 2013-03-16 04:22:16