問題描述

我想將建立的標記從標準 (dl) 更改為具有差異的 unordered-list 。以下是所需的標記:

<ul>
    <li><a href="/path/to/image.jpg"><img src="/path/to/image.jpg" /></a></li>
    <li><a href="/path/to/image2.jpg"><img src="/path/to/image2.jpg" /></a></li>
    <!-- And so on, all in one ul -->
</ul> 

我想要主影像源的連結& img,因為我想透過 php cropper 指令碼執行 img src 。

這可能嗎?我相信我們可以破解它!

最佳解決方案

感謝您的回覆,Jan& Rarst 。他們指出我正確的方向。這是我結束的。

這將停用內容中的縮寫。完美的這個網站& 該功能附加影像& 吐出來作為列表。 (我發現這個功能在某處,並將它縮小一點)

// Removed shortcodes from the content
add_filter('the_content', 'strip_shortcodes');

// Get attached images & spits out a list of them.
function nerdy_get_images($size = 'thumbnail', $limit = '0', $offset = '0') {
    global $post;
    $images = get_children( array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') );
    if ($images) {
        $num_of_images = count($images);
        if ($offset > 0) : $start = $offset--; else : $start = 0; endif;
        if ($limit > 0) : $stop = $limit+$start; else : $stop = $num_of_images; endif;
        $i = 0;
        foreach ($images as $image) {
            if ($start <= $i and $i < $stop) {
            $img_title = $image->post_title;   // title.
            $img_description = $image->post_content; // description.
            $img_caption = $image->post_excerpt; // caption.
            $img_url = wp_get_attachment_url($image->ID); // url of the full size image.
            $preview_array = image_downsize( $image->ID, $size );
            $img_preview = $preview_array[0]; // thumbnail or medium image to use for preview.
            ?>
            <li>
                <a href="http://<?php%20echo%20$img_url;%20?>"><img src="<?php echo $img_preview; ?>" alt="<?php echo $img_caption; ?>" title="<?php echo $img_title; ?>"></a>
            </li>
            <?
            }
            $i++;
        }
    }
}

這是在 single.php 中的呼叫

<ul>
    <?php nerdy_get_images('medium','0','0'); ?>
</ul>

這完全是我想要的一個清單。

再次感謝你們!

次佳解決方案

gallery_shortcode()功能中的專案輸出沒有被過濾,所以沒有機會改變它。標記只能使用在開始執行的 post_gallery 過濾器完全替換。與通常的過濾最終結果相比,這是一個非常規的方法,可能是出於效能原因 (生成庫可能在計算上很重) 。

但它使用 wp_get_attachment_link()生成連結,其輸出透過 wp_get_attachment_link 鉤子與大量的細節進行過濾:

apply_filters( 'wp_get_attachment_link', "<a href='$url' title='$post_title'>$link_text</a>", $id, $size, $permalink, $icon, $text );

你需要執行一些非常複雜的作品,你想要單獨的指令碼來處理它嗎?為什麼不讓 WP 用 add_image_size()處理它?

參考文獻

注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。