更改代码以显示图像附件页面

时间:2012-12-04 作者:10wtaylor

我有这个代码,它在列表中显示带有标题的图像。单击标题,会在附件页中打开图像,但单击图像,会打开背景为深灰色的图像。是否有一种方法可以在单击附件页时在其上显示图像??我玩了很多,但没有成功。

$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" />\';
    }

2 个回复
最合适的回答,由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" />\';
}

结束

相关推荐

Images in wp_mail not showing

我创建了一个发送电子邮件的插件:$subject = \'New comment - \'.$post_title; ob_start(); include(SUBSCRIBE_USER_BASE_DIR . \'/email/message.php\'); $message = ob_get_clean(); foreach($user_emails as $user_email){ $to = $user