• 24-06-2023, 18:13:57
    #1
    Yapmaya çalıştığım şey

    konuya insert ettiğim resimleri yine konu içerisine yaymak en altta galeri şeklinde çok basit duruyor.

    her h2 tagından sonra 1 resim eklemeye çalışıyorum bir türlü yapamadım (elle yerleştirmeyi ben de biliyorum.)

    kod şudur.

    <?php 
    
    $content = get_the_content(); // İçeriği al
    
    $attachments = get_posts(array(
        'post_type' => 'attachment',
        'order' => 'desc',
        'numberposts' => 10,
        'post_status' => null,
        'post_parent' => $post->ID
    ));
    
    if ($attachments) {
        $attachment_index = 0; // Attachment indexini takip etmek için bir sayaç
        $content_parts = explode('</h2>', $content); // İçeriği </p> etiketlerine göre bölelim
    
        foreach ($content_parts as $content_part) {
            echo $content_part . '</h2>'; // İçerik bölümünü yazdır
    
            if ($attachment_index < count($attachments)) {
                $attachment = $attachments[$attachment_index];
                $attlink  = get_attachment_link($attachment->ID);
                $img_src   = wp_get_attachment_url($attachment->ID);
                $atttitle = $attachment->post_title;
                $imgalt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
                //echo "<p>$attachment->post_title</p>";
                echo "<span class=\"image fit\"><a href=\"$img_src\" data-lightbox=\"box alt-images\">";
                echo "<img src=\"$img_src\" alt=\"$imgalt\"/>";
                echo "</a></span>";
    
                $attachment_index++; // Sıradaki attachment için sayaç artırılıyor
            }
        }
    }
    
    ?>

    Hata düzeltildi lazım olan olursa kullanabilir.
  • 24-06-2023, 18:29:41
    #2
    Neyi olmuyor? Şunu değiştirin:

    echo $part.'</h2>';