• 12-12-2010, 23:55:02
    #1
    Arkadaşlar merhaba,

    Kullandığım bir wordpress'te özel alan olarak resimleri her yazıya daha kolay bir şekilde gösteriyorum...

    Ancak bu konuda bir sorunum var.

    Eklediğim resimler sayfada göründüğünde titleye sahip olmuyor.

    Örnek ali diye bir konu açtım ve ali resmini özel alanlarda IMAGE tağı ile ekledim..

    Haliyle single.php de ki

    <img src="<?php echo get_post_meta($post->ID, 'Image', true); ?>"/>
    Bu kod aracılığı ile de konu içerisinde bu resmi gösterebiliyorum..

    Şimdi yapmak istediğim bu resim de title ekleyebilmek yani resim adını resim kodu içerisinde göstermek istiyorum.

    Şuanda sayfadan şu sonucu alıyorum;
    <img src="http://www.siteadi.com/ali.jpg">

    Ancak almak istediğim sonuç şu;
    <img src="http://www.siteadi.com/ali.jpg" title="ali">

    Ve

    <img src="<?php echo get_post_meta($post->ID, 'Image', true); ?>"/>
    Bu kodda şu değişikliği yapınca ;

    <img title="<?php the_title(); ?>" src="<?php echo get_post_meta($post->ID, 'Image', true); ?>"/>
    Sadece ekstra olarak resim koduna konunun adını yazabiliyorum, benim istediğim title'de resimin ismini yazdırmak..


    Bu konuda bilgisi olan var mı acaba ?
  • 13-12-2010, 00:06:01
    #2
    yardımcı olurmu bilmiyorum fakat

    /**
    * Retrieves the attachment data such as Title, Caption, Alt Text, Description
    * @param int $post_id the ID of the Post, Page, or Custom Post Type
    * @param String $size The desired image size, e.g. thumbnail, medium, large, full, or a custom size
    * @return stdClass If there is only one result, this method returns a generic
    * stdClass object representing each of the image's properties, and an array if otherwise.
    */
    function getImageAttachmentData( $post_id, $size = 'thumbnail', $count = 1 )
    {
    $objMeta = array();
    $meta;// (stdClass)
    $args = array(
    'numberposts' => $count,
    'post_parent' => $post_id,
    'post_type' => 'attachment',
    'nopaging' => false,
    'post_mime_type' => 'image',
    'order' => 'ASC', // change this to reverse the order
    'orderby' => 'menu_order ID', // select which type of sorting
    'post_status' => 'any'
    );
    
    $attachments = & get_children($args);
    
    if( $attachments )
    {
    foreach( $attachments as $attachment )
    {
    $meta = new stdClass();
    $meta->ID = $attachment->ID;
    $meta->title = $attachment->post_title;
    $meta->caption = $attachment->post_excerpt;
    $meta->description = $attachment->post_content;
    $meta->alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
    
    // Image properties
    $props = wp_get_attachment_image_src( $attachment->ID, $size, false );
    
    $meta->properties['url'] = $props[0];
    $meta->properties['width'] = $props[1];
    $meta->properties['height'] = $props[2];
    
    $objMeta[] = $meta;
    }
    
    return ( count( $attachments ) == 1 ) ? $meta : $objMeta;
    }
    }
    kullanımı
    getImageAttachmentData( $_posts->ID, 'full' );
  • 13-12-2010, 00:12:41
    #3
    <img title="<?php the_title(); ?>" src="<?php echo get_post_meta($post->ID, 'Image', true); ?>"/>

    Bu kodu bu şekilde kullanın birde:
    <img src="<?php echo get_post_meta($post->ID, 'Image', true); ?>" title="<?php the_title(); ?>"/>
  • 13-12-2010, 00:37:31
    #4
    Aşağıdaki kod yardımıyla yapabilirsiniz.
    <?php
     $resim=get_post_meta($post->ID, 'Image', true);
     $ad=basename($resim);
     $parts = explode('.', basename($resim));
     $ad = basename($ad, '.'.$parts[count($parts)-1]);
     echo '<img src="'.$resim.'" title="'.$ad.'" />';
    ?>
  • 13-12-2010, 01:19:38
    #5
    Tekrar özel alan kullanarak ismi elle de girebilirsiniz
  • 13-12-2010, 15:33:41
    #6
    Yardımlarınız için çok teşekkür ederim arkadaşlar, @yakuphan tam istediğim gibi eline sağlık.

    İyi çalışmalar.