
resim_cagirma.php
<?php
function resim_cagir($index, $default_image='', $img_class='post-image')
{
if(!in_the_loop())
{
trigger_error("aradiginiz resim su ana bulunamiyor", E_USER_ERROR);
return 0;
}
echo(gpi_get_image($index, $default_image, true, $img_class));
}
/*
Plugin Name: Wordpress resim ekleme
Plugin URI: http://blog.olcaybal.com/index.php/programlar/wordpresste-sadece-resim-gsterme-get-post-image-for-wordpress
Description: Wordpress icinde sadace resim gostermek icin pratik bir cozum
Version: 1.0
Author: Olcay BAL
Author URI: http://www.olcaybal.com/
******************************************************************************************/
function gpi_get_image_count()
{
global $post;
if(!in_the_loop())
{
trigger_error("gpi_get_image_count can only be used within the post loop", E_USER_ERROR);
return 0;
}
$image_list = gpi_internal_cache_imagelist($post);
return count($image_list);
}
/******************************************************************************************
resim içerik olustuam ölümü ve spesicic deger ama functionu
******************************************************************************************/
function gpi_get_image($index, $default_image='', $as_tag=true, $img_class='post-image')
{
global $post;
if(!in_the_loop())
{
trigger_error("gpi_get_image can only be used within the post loop", E_USER_ERROR);
return 0;
}
$info = gpi_internal_get_image_info($post, $index, $default_image);
if($as_tag)
{
$image = '<img class="' . $img_class . '" src="' . $info['url'] . '" ' . $info['size'] . ' title="' . $info['title'] . '" alt="' . $info['title'] . '" />';
}
else
{
$image = $info;
}
return $image;
}
/******************************************************************************************
RESIM url DOYASINI ÇAGIRACAGIN ALAN
******************************************************************************************/
/*****************************************************************************************
**
** Internal FUNCION ALANI
**
*****************************************************************************************/
// specified image indexleme
$gpi_image_list_cache = array();
/******************************************************************************************
caches imahe indexleme
******************************************************************************************/
function gpi_internal_cache_imagelist($post)
{
global $gpi_image_list_cache;
if (!isset($gpi_image_list_cache[$post->ID]))
{
//path yolunda url arama alani
$match_count = preg_match_all("/<img[^']*?src=\"([^']*?)\"[^']*?>/", $post->post_content, $match_array, PREG_PATTERN_ORDER);
$gpi_image_list_cache[$post->ID] = $match_array[1];
}
return $gpi_image_list_cache[$post->ID];
}
/******************************************************************************************
image listeleme alani
******************************************************************************************/
function gpi_internal_get_image_info($post, $index, $default_image='')
{
$image_list = gpi_internal_cache_imagelist($post);
if ($index < count($image_list))
{
$img_url = $image_list[$index];
}
else
{
$img_url = $default_image;
}
// url özellikleri
$img_url = urldecode($img_url);
// server get url alani
$img_path = ABSPATH . str_replace(get_settings('siteurl'), '', $img_url);
// image döngüleme alani
if(file_exists($img_path))
{
$imagesize = @getimagesize($img_url);
}
else
{
$imagesize=array();
}
// resim alani
$info = array('title' => $post->post_title, // resim titlesi
'url' => $img_url, // resim urlsi
'size' => $imagesize[3], //reism image size (e.g height="60" width="120")
'width' => $imagesize[0], // sadece genislik
'height' => $imagesize[1], // sadece yukseklik
'path' => $img_path, // local path
'type' => $imagesize[2]); // image ozellik
return $info;
}
?>