• 19-07-2019, 20:37:34
    #1
    Selamlar arkadaşlar,
    Diyelim ki siteye haber ajanslarından otomatik eklenen haberler var ve bunların bazıları öne çıkan görsel olmadan ekleniyor. İşte bunlara bizim belirlediğimiz standart bir resim ekleyecek eklenti veya kod bileniniz var mıdır?
  • 20-07-2019, 11:59:11
    #2
    Merhaba,

    Aşağıdaki kodu kendinize göre düzenleyin. Eğer varsa öne çıkan görseli yoksa tema klasöründeki bir görseli gösterir.

    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
    <?php
    if ( has_post_thumbnail() ) {
    the_post_thumbnail();
    } else {
    ?>
    <img src="<?php bloginfo('template_url')?>/images/haber.jpg">
    <?php }?>
    </a>
  • 20-07-2019, 17:37:09
    #3
    Kimlik doğrulama veya yönetimden onay bekliyor.
    Yukarıdaki kod işinizi görmezse alternatif olması açısından bu kodu da kullanabilirsiniz.Temazının functions.php dosyasına ekledikten sonra yeni eklenen yazının ilk resmini otomatik olarak "öne çıkarılan görsel" yapacaktır.Eski yazılardaki sorunları çözmek içinde yapmanız gereken,yazıları tek tek güncellemek.

    function autoset_featured() {
    global $post;
    $already_has_thumb = has_post_thumbnail($post->ID);
    if (!$already_has_thumb) {
    $attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
    if ($attached_image) {
    foreach ($attached_image as $attachment_id => $attachment) {
    set_post_thumbnail($post->ID, $attachment_id);
    }
    }
    }
    } //end function
    add_action('the_post', 'autoset_featured');
    add_action('save_post', 'autoset_featured');
    add_action('draft_to_publish', 'autoset_featured');
    add_action('new_to_publish', 'autoset_featured');
    add_action('pending_to_publish', 'autoset_featured');
    add_action('future_to_publish', 'autoset_featured');
  • 23-07-2019, 02:01:23
    #4
    temistan adlı üyeden alıntı: mesajı görüntüle
    Merhaba,

    Aşağıdaki kodu kendinize göre düzenleyin. Eğer varsa öne çıkan görseli yoksa tema klasöründeki bir görseli gösterir.

    <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
    <?php
    if ( has_post_thumbnail() ) {
    the_post_thumbnail();
    } else {
    ?>
    <img src="<?php bloginfo('template_url')?>/images/haber.jpg">
    <?php }?>
    </a>
    Kod çalışmıyor. Ölümcül hata var diyor.