wmaraci reklam
lidertakipci

Bu değişkeni nasıl aktif edebilirim?

28 Mesajlar 2.485 Okunma
advertseo
wmaraci reklam

emlcvdv emlcvdv WM Aracı Kullanıcı
  • Üyelik 05.02.2014
  • Yaş/Cinsiyet 31 / E
  • Meslek webmaster
  • Konum İstanbul Anadolu
  • Ad Soyad E** C**
  • Mesajlar 98
  • Beğeniler 3 / 7
  • Ticaret 1, (%100)
Merhaba arkadaşlar. PHP bilmediğimden şu sorunu halledemedim. Sizlerden yardım bekliyorum. wp-includes/media.php dosyasında 2 tane fonksiyondan birinde işe yarayan bir değişken diğerinde işe yaramıyor. Değişken şu: esc_attr($alt)

Fonksiyonlar ise şunlar;

1. Fonksiyon

function get_image_tag($id, $alt, $title, $align, $size='medium') {

list( $img_src, $width, $height ) = image_downsize($id, $size);
$hwstring = image_hwstring($width, $height);

$title = $title ? 'title="' . esc_attr( $title ) . '" ' : '';

$class = 'align' . esc_attr($align) .' size-' . esc_attr($size) . ' wp-image-' . $id;

/**
* Filter the value of the attachment's image tag class attribute.
*
* @since 2.6.0
*
* @param string $class CSS class name or space-separated list of classes.
* @param int $id Attachment ID.
* @param string $align Part of the class name for aligning the image.
* @param string $size Optional. Default is 'medium'.
*/
$class = apply_filters( 'get_image_tag_class', $class, $id, $align, $size );

$html = '' . esc_attr($alt) . '';

/**
* Filter the HTML content for the image tag.
*
* @since 2.6.0
*
* @param string $html HTML content for the image.
* @param int $id Attachment ID.
* @param string $alt Alternate text.
* @param string $title Attachment title.
* @param string $align Part of the class name for aligning the image.
* @param string $size Optional. Default is 'medium'.
*/
$html = apply_filters( 'get_image_tag', $html, $id, $alt, $title, $align, $size );

return $html;
}


2. Fonksiyon:

function img_caption_shortcode( $attr, $content = null ) {
// New-style shortcode with the caption inside the shortcode with the link and image tags.
if ( ! isset( $attr['caption'] ) ) {
if ( preg_match( '#((?:]+>\s*)?]+>(?:\s*)?)(.*)#is', $content, $matches ) ) {
$content = $matches[1];
$attr['caption'] = trim( $matches[2] );
}
}

/**
* Filter the default caption shortcode output.
*
* If the filtered output isn't empty, it will be used instead of generating
* the default caption template.
*
* @since 2.6.0
*
* @see img_caption_shortcode()
*
* @param string $output The caption output. Default empty.
* @param array $attr Attributes of the caption shortcode.
* @param string $content The image element, possibly wrapped in a hyperlink.
*/
$output = apply_filters( 'img_caption_shortcode', '', $attr, $content );
if ( $output != '' )
return $output;

$atts = shortcode_atts( array(
'id' => '',
'align' => 'alignnone',
'width' => '',
'caption' => '',
'class' => '',
'alt' => '',
), $attr, 'caption' );

$atts['width'] = (int) $atts['width'];
if ( $atts['width'] < 1 || empty( $atts['caption'] ) )
return $content;

if ( ! empty( $atts['id'] ) )
$atts['id'] = 'id="' . esc_attr( $atts['id'] ) . '" ';

$class = trim( 'wp-caption ' . $atts['align'] . ' ' . $atts['class'] );

if ( current_theme_supports( 'html5', 'caption' ) ) {
return '
'
. do_shortcode( $content ) . '
' . $atts['caption'] . '
';
}

$caption_width = 10 + $atts['width'];

/**
* Filter the width of an image's caption.
*
* By default, the caption is 10 pixels greater than the width of the image,
* to prevent post content from running up against a floated image.
*
* @since 3.7.0
*
* @see img_caption_shortcode()
*
* @param int $caption_width Width of the caption in pixels. To remove this inline style,
* return zero.
* @param array $atts Attributes of the caption shortcode.
* @param string $content The image element, possibly wrapped in a hyperlink.
*/

$caption_width = apply_filters( 'img_caption_shortcode_width', $caption_width, $atts, $content );

$style = '';
if ( $caption_width )
$style = 'style="width: ' . (int) $caption_width . 'px" ';

return '

' . $atts['caption'] . '

'
. do_shortcode( $content ) . '

' . esc_attr($alt) . '

';
}


Benim sorum şu: 1. Fonksiyondaki esc_attr($alt) değişkeni resimlerin alternatif yazılarını çekebiliyorken 2. Fonksiyondaki esc_attr($alt) değişkeni bunu yapamıyor. esc_attr($alt) değişkenini 2. Fonksiyonda da etkin hale nasıl getirebilirim?
 

 

wmaraci
reklam

TEHET TEHET Kullanıcı
  • Üyelik 04.10.2014
  • Yaş/Cinsiyet 31 / E
  • Meslek Tasarımcı
  • Konum Ankara
  • Ad Soyad M** A**
  • Mesajlar 791
  • Beğeniler 96 / 374
  • Ticaret 1, (%100)
Tamamen sallayarak (:D);
esc_attr($alt)
yerine
esc_attr( get_the_ID() )
belki olabilir.
 

 

emlcvdv emlcvdv WM Aracı Kullanıcı
  • Üyelik 05.02.2014
  • Yaş/Cinsiyet 31 / E
  • Meslek webmaster
  • Konum İstanbul Anadolu
  • Ad Soyad E** C**
  • Mesajlar 98
  • Beğeniler 3 / 7
  • Ticaret 1, (%100)

TEHET adlı üyeden alıntı

Tamamen sallayarak (:D);
esc_attr($alt)
yerine
esc_attr( get_the_ID() )
belki olabilir.


Maalesef hocam. 5809 diye bir sayıyı bastı. Bana ise resme girilen alternatif yazıyı çekecek bir değişken lazım. Yazılara eklenen resimlerin id'sini nasıl alabilirim, bu konu hakkında bilginiz var mı peki?
 

 

mehmetuken mehmetuken WM Aracı Kullanıcı
  • Üyelik 16.12.2014
  • Yaş/Cinsiyet 28 / E
  • Meslek Software Developer
  • Konum Antalya
  • Ad Soyad M** T**
  • Mesajlar 28
  • Beğeniler 0 / 7
  • Ticaret 5, (%100)
esc_attr($atts['alt'])

Bu şekilde olması gerekiyor hocam. o bir değişken değil fonksiyondur haberiniz olsun :D
 

 

wmaraci
wmaraci

cihaneken cihaneken Üyeliği Durdurulmuş Banlı Kullanıcı
  • Üyelik 25.07.2014
  • Yaş/Cinsiyet 30 / E
  • Meslek Elektrik Teknisyeni
  • Konum Fransa
  • Ad Soyad C** E**
  • Mesajlar 3510
  • Beğeniler 488 / 1190
  • Ticaret 1, (%100)





denermisin hocam.
 

 

TEHET TEHET Kullanıcı
  • Üyelik 04.10.2014
  • Yaş/Cinsiyet 31 / E
  • Meslek Tasarımcı
  • Konum Ankara
  • Ad Soyad M** A**
  • Mesajlar 791
  • Beğeniler 96 / 374
  • Ticaret 1, (%100)

emlcvdv adlı üyeden alıntı

Maalesef hocam. 5809 diye bir sayıyı bastı. Bana ise resme girilen alternatif yazıyı çekecek bir değişken lazım. Yazılara eklenen resimlerin id'sini nasıl alabilirim, bu konu hakkında bilginiz var mı peki?


if ( has_post_thumbnail() ) {
$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'large' );
echo '';
echo get_the_post_thumbnail( $post->ID, 'thumbnail' );
echo '
';
}
?>


Şu tarz bir koddu yanılmıyorsam. Bir ara en çok beğenilen yazılar widgetinde resimleri gösterebilmek için kullanmıştım galiba.

http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail
 

 

emlcvdv emlcvdv WM Aracı Kullanıcı
  • Üyelik 05.02.2014
  • Yaş/Cinsiyet 31 / E
  • Meslek webmaster
  • Konum İstanbul Anadolu
  • Ad Soyad E** C**
  • Mesajlar 98
  • Beğeniler 3 / 7
  • Ticaret 1, (%100)

mehmetuken adlı üyeden alıntı

Bu şekilde olması gerekiyor hocam. o bir değişken değil fonksiyondur haberiniz olsun :D


İşte php bilmediğimin kanıtı :) Öğrenmiş oldum teşekkür ederim. Bu arada verdiğiniz kod işe yaramadı maalesef. Hiçbir şey basmadı ekrana.

Ek Olarak:

Maalesef işe yaramadı hocam. Hiçbir şey basmadı ekrana.

Ek Olarak:

TEHET adlı üyeden alıntı

if ( has_post_thumbnail() ) {
$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'large' );
echo '';
echo get_the_post_thumbnail( $post->ID, 'thumbnail' );
echo '
';
}
?>


Şu tarz bir koddu yanılmıyorsam. Bir ara en çok beğenilen yazılar widgetinde resimleri gösterebilmek için kullanmıştım galiba.

http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail


Hocam bu farklı. Bu, öne çıkarılan resmin alternatif yazısını çekiyor.

Mesela aşağıdaki kodları eklediğimde öne çıkarılan resmin alternatif yazısını çekebiliyorum ama benim istediğim şey, her upload edilmiş ve yazıya eklenmiş resmin alternatif yazısını çekebilecek bir kod..

$img_id = get_post_thumbnail_id( $post_id );
$alt_text = get_post_meta( $img_id, '_wp_attachment_image_alt', true );
 

 

mehmetuken mehmetuken WM Aracı Kullanıcı
  • Üyelik 16.12.2014
  • Yaş/Cinsiyet 28 / E
  • Meslek Software Developer
  • Konum Antalya
  • Ad Soyad M** T**
  • Mesajlar 28
  • Beğeniler 0 / 7
  • Ticaret 5, (%100)

$img_id = get_post_thumbnail_id( $post_id );
$alt_text = get_post_meta( $img_id, '_wp_attachment_image_alt', true );


hocam bu kod o işlemi yapıyor mu ? yani yazıyı getiriyo mu ?
 

 

emlcvdv emlcvdv WM Aracı Kullanıcı
  • Üyelik 05.02.2014
  • Yaş/Cinsiyet 31 / E
  • Meslek webmaster
  • Konum İstanbul Anadolu
  • Ad Soyad E** C**
  • Mesajlar 98
  • Beğeniler 3 / 7
  • Ticaret 1, (%100)

mehmetuken adlı üyeden alıntı

hocam bu kod o işlemi yapıyor mu ? yani yazıyı getiriyo mu ?


Eğer resim öne çıkarılmışsa, $alt_text değişkeni ile o resmin alternatif yazısını çekebiliyorum evet.
 

 

mehmetuken mehmetuken WM Aracı Kullanıcı
  • Üyelik 16.12.2014
  • Yaş/Cinsiyet 28 / E
  • Meslek Software Developer
  • Konum Antalya
  • Ad Soyad M** T**
  • Mesajlar 28
  • Beğeniler 0 / 7
  • Ticaret 5, (%100)

emlcvdv adlı üyeden alıntı

Eğer resim öne çıkarılmışsa, $alt_text değişkeni ile o resmin alternatif yazısını çekebiliyorum evet.


O zaman 2. fonksiyonun içine ekleyin o kodu esc_attr($alt) yazan yerede $alt_text yazın.
 

 

wmaraci
Konuyu toplam 1 kişi okuyor. (0 kullanıcı ve 1 misafir)
Site Ayarları
  • Tema Seçeneği
  • Site Sesleri
  • Bildirimler
  • Özel Mesaj Al