Merhabalar, aşağıdaki kodla bazı eklentilerde yazı başlığını kısaltmama rağmen son yorumlanan yazılar (recent-commented-posts) eklentisinde bunu yapamadım.

// Yazı Başlığını Kısaltma
function baslik() {
$baslik = get_the_title();
if(strlen($baslik) > 30) {
$baslik = mb_substr($baslik, 0, 30) . '...';
}
echo $baslik;
}


Son Yorumlanan Yazılar (recent-commented-posts) eklentisinde şu kod yok;



Bu eklentide yazı başlığını nasıl kısaltabilirim? Eklentinin kodları aşağıda.

/*
Plugin Name: Recent Commented Posts
Plugin URI: http://www.yakupgovler.com/?p=1056
Description: Displays most recently commented posts with thumbnail images (optional).
Version: 1.1
Author: Yakup GÖVLER
Author URI: http://www.yakupgovler.com
*/
/*
TODO: Add cache
*/
class yg_recent_commented_posts extends WP_Widget {
function yg_recent_commented_posts() {
//Load Language
load_plugin_textdomain( 'recent-commented-posts', false, dirname(plugin_basename(__FILE__)) . '/lang' );
$widget_ops = array('description' => __('Displays most recently commented commented posts. You can customize it easily.', 'recent-commented-posts') );
//Create widget
$this->WP_Widget('recentcommentedposts', __('Recent Commented Posts', 'recent-commented-posts'), $widget_ops);
}

function widget($args, $instance) {
extract($args, EXTR_SKIP);
echo $before_widget;
$title = empty($instance['title']) ? __('Recent Commented Posts', 'recent-commented-posts') : apply_filters('widget_title', $instance['title']);
$parameters = array(
'title' => $title,
'limit' => (int) $instance['show-num'],
'excerpt' => (int) $instance['excerpt-length'],
'cusfield' => esc_attr($instance['cus-field']),
'w' => (int) $instance['width'],
'h' => (int) $instance['height'],
'firstimage' => (bool) $instance['firstimage'],
'atimage' =>(bool) $instance['atimage'],
'defimage' => esc_url($instance['defimage'])
);

if ( !empty( $title ) ) {
echo $before_title . $title . $after_title;
};
//print Recent Commented Posts
yg_recentcommentedposts($parameters);
echo $after_widget;
} //end of widget

//Update widget options
function update($new_instance, $old_instance) {

$instance = $old_instance;
//get old variables
$instance['title'] = esc_attr($new_instance['title']);
$instance['show-num'] = (int) abs($new_instance['show-num']);
if ($instance['show-num'] > 20) $instance['show-num'] = 20;
$instance['excerpt-length'] = (int) abs($new_instance['excerpt-length']);
$instance['cus-field'] = esc_attr($new_instance['cus-field']);
$instance['width'] = esc_attr($new_instance['width']);
$instance['height'] = esc_attr($new_instance['height']);
$instance['firstimage'] = $new_instance['first-image'] ? 1 : 0;
$instance['atimage'] = $new_instance['atimage'] ? 1 : 0;
$instance['defimage'] = esc_url($new_instance['def-image']);
return $instance;
} //end of update

//Widget options form
function form($instance) {
$instance = wp_parse_args( (array) $instance, array( 'title' => __('Recent Commented Posts','recent-commented-posts'), 'show-num' => 10, 'excerpt-length' => 0, 'cus-field' => '', 'width' => '', 'height' => '', 'firstimage' => 0, 'atimage' => 0,'defimage'=>'' ) );

$title = esc_attr($instance['title']);
$show_num = (int) $instance['show-num'];
$excerpt_length = (int) $instance['excerpt-length'];
$cus_field = esc_attr($instance['cus-field']);
$width = esc_attr($instance['width']);
$height = esc_attr($instance['height']);
$firstimage = (bool) $instance['firstimage'];
$atimage = (bool) $instance['atimage'];
$defimage = esc_url($instance['defimage']);

?>














/>



/>








px

px


} //end of form
}

add_action( 'widgets_init', create_function('', 'return register_widget("yg_recent_commented_posts");') );
//Register Widget

// Show Recent Commented Posts function
function yg_recentcommentedposts($args = '') {
global $wpdb;
$defaults = array('limit' => 10, 'excerpt' => 0, 'cusfield' =>'', 'w' => 48, 'h' => 48, 'firstimage' => 0, 'atimage' => 0, 'defimage' => '');
$args = wp_parse_args( $args, $defaults );
extract($args);

$limit = (int) abs($limit);
$firstimage = (bool) $firstimage;
$atimage = (bool) $atimage;
$defimage = esc_url($defimage);
$w = (int) $w;
$h = (int) $h;

$excerptlength = (int) abs($excerpt);
$excerpt = '';

if (($limit < 1 ) || ($limit > 20)) $limit = 10;

$height = $h ? ' height = "' . $h .'"' : '';
$width = $w ? ' width = "' . $w . '"' : '';

$sql = "SELECT ID, post_title, post_content, post_excerpt FROM $wpdb->posts JOIN $wpdb->comments ON $wpdb->posts.ID=$wpdb->comments.comment_post_ID WHERE comment_ID IN (SELECT MAX(comment_ID) FROM $wpdb->comments WHERE comment_approved = '1' AND comment_type='' AND comment_post_ID = $wpdb->posts.ID GROUP BY comment_post_ID) AND post_status ='publish' AND post_type='post' AND post_password ='' ORDER BY comment_ID DESC LIMIT $limit";
$posts = $wpdb->get_results($sql);
$postlist = '';
foreach ($posts as $post) {
$post_title = esc_attr($post->post_title);
if ($excerptlength) {
$excerpt = $post->post_excerpt;
if ( '' == $excerpt ) {
$text = $post->post_content;
$text = strip_shortcodes( $text );
$text = str_replace(']]>', ']]>', $text);
$text = strip_tags($text);
$excerpt_length = 100;
$words = explode(' ', $text, $excerpt_length + 1);
if (count($words) > $excerpt_length) {
array_pop($words);
$text = implode(' ', $words);
}
$excerpt = $text;
}

if(strlen($excerpt) > $excerptlength) {
$excerpt = mb_substr($excerpt, 0, $excerptlength) . '...';
}
$excerpt = ': ' . $excerpt;
}
$image = '';
$img = '';
if ($cusfield) {
$cusfield = esc_attr($cusfield);
$img = get_post_meta($post->ID, $cusfield, true);
}

if (!$img && $firstimage) {
$match_count = preg_match_all("//", $post->post_content, $match_array, PREG_PATTERN_ORDER);
$img = $match_array[1][0];
}
if (!$img && $atimage) {
$p = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'numberposts' => 1,
'order' => 'ASC',
'orderby' => 'menu_order ID',
'post_status' => null,
'post_parent' => $post->ID
);
$attachments = get_posts($p);
if ($attachments) {
$imgsrc = wp_get_attachment_image_src($attachments[0]->ID, 'thumbnail');
$img = $imgsrc[0];
}
}

if (!$img && $defimage)
$img = $defimage;

if ($img)
$image = '';


$postlist .= "
  • ID) . "\" title=\"". $post_title ."\" >$image" . $post_title ."$excerpt
  • \n";
    }

    echo '
      ';
      echo $postlist;
      echo '
    ';
    }

    ?>