我有这个代码,它在列表中显示带有标题的图像。单击标题,会在附件页中打开图像,但单击图像,会打开背景为深灰色的图像。是否有一种方法可以在单击附件页时在其上显示图像??我玩了很多,但没有成功。
$i = 0;
$rand_id = mt_rand(1,1000);
foreach ( $attachments as $id => $attachment ) {
$image_attributes = wp_get_attachment_image_src( $id,\'large\' );
$link = isset($attr[\'link\']) && \'file\' == $attr[\'link\'] ? \'<a href="\'.$image_attributes[0].\'" rel="prettyPhoto[pp_\'.$rand_id.\']"><span class="mosaic-overlay"></span>\'.wp_get_attachment_image($id, $size, false).\'</a>\' : \'<a href="\'.$image_attributes[0].\'" rel="prettyPhoto[pp_\'.$rand_id.\']"><span class="mosaic-overlay"></span>\'.wp_get_attachment_image($id, $size, false).\'</a>\';
$output .= "<{$itemtag} class=\'gallery-item\'>";
$output .= "
<{$icontag} class=\'gallery-icon\'>
$link
</{$icontag}>";
if ( $captiontag && trim($attachment->post_title) ) { //caption display
$output .= "
<{$captiontag} class=\'gallery-caption\'>
" .wp_get_attachment_link($id, $size, true, false, wptexturize($attachment->post_title)) . "
</{$captiontag}>";
}
$output .= "</{$itemtag}>";
if ( $columns > 0 && ++$i % $columns == 0 )
$output .= \'<br style="clear: both" />\';
}
最合适的回答,由SO网友:Mridul Aggarwal 整理而成
正如另一个答案所指出的,你不应该有分手的机会
应更改链接以使用该功能get_attachment_link
基本上更改代码中的这一行
$link = \'<a href="\'.get_attachment_link($id).\'">\'.wp_get_attachment_image($id, $size, false).\'</a>\';
SO网友:Danny Michel
看起来应该删除Prettypoto部分,例如
$i = 0;
$rand_id = mt_rand(1,1000);
foreach ( $attachments as $id => $attachment ) {
$image_attributes = wp_get_attachment_image_src( $id,\'large\' );
$link = isset($attr[\'link\']) && \'file\' == $attr[\'link\'] ? \'<a href="\'.$image_attributes[0].\'" ]">\'.wp_get_attachment_image($id, $size, false).\'</a>\' : \'<a href="\'.$image_attributes[0].\'" ]">\'.wp_get_attachment_image($id, $size, false).\'</a>\';
$output .= "<{$itemtag} class=\'gallery-item\'>";
$output .= "
<{$icontag} class=\'gallery-icon\'>
$link
</{$icontag}>";
if ( $captiontag && trim($attachment->post_title) ) { //caption display
$output .= "
<{$captiontag} class=\'gallery-caption\'>
" .wp_get_attachment_link($id, $size, true, false, wptexturize($attachment->post_title)) . "
</{$captiontag}>";
}
$output .= "</{$itemtag}>";
if ( $columns > 0 && ++$i % $columns == 0 )
$output .= \'<br style="clear: both" />\';
}