Vanilla 1.1.10 es un producto de Lussumo. Para más información: Documentación, Soporte.
/**
* Recent_Comments widget class
*
* @since 2.8.0
*/
class WP_Widget_Recent_Comments extends WP_Widget {
function WP_Widget_Recent_Comments() {
$widget_ops = array('classname' => 'widget_recent_comments', 'description' => __( 'The most recent comments' ) );
$this->WP_Widget('recent-comments', __('Recent Comments'), $widget_ops);
$this->alt_option_name = 'widget_recent_comments';
if ( is_active_widget(false, false, $this->id_base) )
add_action( 'wp_head', array(&$this, 'recent_comments_style') );
add_action( 'comment_post', array(&$this, 'flush_widget_cache') );
add_action( 'transition_comment_status', array(&$this, 'flush_widget_cache') );
}
function recent_comments_style() { ?>
<style type="text/css">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style>
<?php
}
function flush_widget_cache() {
wp_cache_delete('widget_recent_comments', 'widget');
}
function widget( $args, $instance ) {
global $comments, $comment;
$cache = wp_cache_get('widget_recent_comments', 'widget');
if ( ! is_array( $cache ) )
$cache = array();
if ( isset( $cache[$args['widget_id']] ) ) {
echo $cache[$args['widget_id']];
return;
}
extract($args, EXTR_SKIP);
$output = '';
$title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Comments') : $instance['title']);
if ( ! $number = (int) $instance['number'] )
$number = 5;
else if ( $number < 1 )
$number = 1;
$comments = get_comments( array( 'number' => $number, 'status' => 'approve' ) );
$output .= $before_widget;
if ( $title )
$output .= $before_title . $title . $after_title;
$output .= '<ul id="recentcomments">';
if ( $comments ) {
foreach ( (array) $comments as $comment) {
$output .= '<li class="recentcomments">' . /* translators: comments widget: 1: comment author, 2: post link */ sprintf(_x('%2$s', 'widgets'), get_comment_author_link(), '<a href="' . esc_url( get_comment_link($comment->comment_ID) ) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>';
}
}
$output .= '</ul>';
$output .= $after_widget;
echo $output;
$cache[$args['widget_id']] = $output;
wp_cache_set('widget_recent_comments', $cache, 'widget');
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['number'] = (int) $new_instance['number'];
$this->flush_widget_cache();
$alloptions = wp_cache_get( 'alloptions', 'options' );
if ( isset($alloptions['widget_recent_comments']) )
delete_option('widget_recent_comments');
return $instance;
}
function form( $instance ) {
$title = isset($instance['title']) ? esc_attr($instance['title']) : '';
$number = isset($instance['number']) ? absint($instance['number']) : 5;
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p>
<p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of comments to show:'); ?></label>
<input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" size="3" /></p>
if(strlen($titulo) > 60) { $titulo=substr($titulo, 0, 60)."..."; } //si el título mide más de 60 caracteres, esto pilla los primeros 60
if(strlen($titulo) > 60) { $titulo=substr($titulo, 0, 60)."..."; } //si el título mide más de 60 caracteres, esto pilla los primeros 60
<?php
function cortarPalabras($titulo,$numPalabras){
$arrayTitulo=explode(' ',$titulo);
$tituloFinal="";
$i=0;
while($i<$numPalabras){
$tituloFinal.=$arrayTitulo[$i];
$i++;
}
return $tituloFinal;
}
f(strlen($title)>60) $title=substr($title,0,strpos($title," ",50))."...";
Posted By: Javi$tituloFinal.=$arrayTitulo[$i];
$tituloFinal.=" ".$arrayTitulo[$i];
X-Y.es
function cortar_titulo( $titulo, $longitud = 60 ) { // Devuelve el título cortado en palabras
// Inicializacion de variables
$longitud -= 3; // Para poner los puntitos
$palabras = explode( ' ', $titulo ); // Separamos por palabras
$resultado = '';
$resultadoTemporal = $palabras[0];
$i = 1;
while( strlen( $resultadoTemporal ) < $longitud ) { // Añadimos palabras mientras sea menor de longitud
$resultado = $resultadoTemporal;
$resultadoTemporal .= ' ' . $palabras[$i];
$i++;
}
if( strlen( $resultado ) == 0 ) // Si el resultado ha quedado vacío porque la primera palabra es menor que la longitud
$resultado = substr( $titulo, 0, $longitud );
return( $resultado . '...' );
}
Posted By: Pedroexplode en vez de implode
Posted By: ignatiusEsto cada vez está más completo... Pero la función ya se depurará más o menos: echadle una mano a integrarla en el widget que es lo que más falta le hace
$title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Comments') : $instance['title']);
$title = cortar_titulo( apply_filters('widget_title', empty($instance['title']) ? __('Recent Comments') : $instance['title'] ) );
Fatal error: Call to undefined function cortar_titulo() in /home/xxx/public_html/xxx/wp-includes/default-widgets.php on line 664
function cortar_titulo( $titulo, $longitud = 60 ) { // Devuelve el título cortado en palabras
// Inicializacion de variables
$longitud -= 3; // Para poner los puntitos
$palabras = explode( ' ', $titulo ); // Separamos por palabras
$resultado = '';
$resultadoTemporal = $palabras[0];
$i = 1;
while( strlen( $resultadoTemporal ) < $longitud ) { // Añadimos palabras mientras sea menor de longitud
$resultado = $resultadoTemporal;
$resultadoTemporal .= ' ' . $palabras[$i];
$i++;
}
if( strlen( $resultado ) == 0 ) // Si el resultado ha quedado vacío porque la primera palabra es menor que la longitud
$resultado = substr( $titulo, 0, $longitud );
return( $resultado . '...' );
}
function widget( $args, $instance ) {
global $comments, $comment;
$cache = wp_cache_get('widget_recent_comments', 'widget');
if ( ! is_array( $cache ) )
$cache = array();
if ( isset( $cache[$args['widget_id']] ) ) {
echo $cache[$args['widget_id']];
return;
}
extract($args, EXTR_SKIP);
$output = '';
$title = cortar_titulo( apply_filters('widget_title', empty($instance['title']) ? __('Recent Comments') : $instance['title'] ) );
if ( ! $number = (int) $instance['number'] )
$number = 5;
else if ( $number < 1 )
$number = 1;
$comments = get_comments( array( 'number' => $number, 'status' => 'approve' ) );
$output .= $before_widget;
if ( $title )
$output .= $before_title . $title . $after_title;
$output .= '';
if ( $comments ) {
foreach ( (array) $comments as $comment) {
$output .= '- ' . /* translators: comments widget: 1: comment author, 2: post link */ sprintf(_x('%2$s', 'widgets'), get_comment_author_link(), 'comment_ID) ) . '">' . get_the_title($comment->comment_post_ID) . '') . '
';
}
}
$output .= '
';
$output .= $after_widget;
echo $output;
$cache[$args['widget_id']] = $output;
wp_cache_set('widget_recent_comments', $cache, 'widget');
}
PEGARLA AQUÍ function cortar_titulo(......
class WP_Widget_Recent_Comments extends WP_Widget {
.....
$title = cortar_titulo(....
$title = $this->cortar_titulo( apply_filters('widget_title', empty($instance['title']) ? __('Recent Comments') : $instance['title'] ) );
$title = $instance->cortar_titulo( apply_filters('widget_title', empty($instance['title']) ? __('Recent Comments') : $instance['title'] ) );
/**
* Recent_Comments widget class
*
* @since 2.8.0
*/
<strong>function cortar_titulo( $titulo, $longitud = 60 ) { // Devuelve el título cortado en palabras
// Inicializacion de variables
$longitud -= 3; // Para poner los puntitos
$palabras = explode( ' ', $titulo ); // Separamos por palabras
$resultado = '';
$resultadoTemporal = $palabras[0];
$i = 1;
while( strlen( $resultadoTemporal ) < $longitud ) { // Añadimos palabras mientras sea menor de longitud
$resultado = $resultadoTemporal;
$resultadoTemporal .= ' ' . $palabras[$i];
$i++;
}
if( strlen( $resultado ) == 0 ) // Si el resultado ha quedado vacío porque la primera palabra es menor que la longitud
$resultado = substr( $titulo, 0, $longitud );
return( $resultado . '...' );
}</strong>
class WP_Widget_Recent_Comments extends WP_Widget {
...
class WP_Widget_Recent_Comments extends WP_Widget {
...
class WP_Widget_Recent_Comments extends WP_Widget {
Aquí sin puntitos
$title = $this->cortar_titulo( apply_filters('widget_title', empty($instance['title']) ? __('Recent Comments') : $instance['title'] ) );
$title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Comments') : $instance['title'] );
$output .= $before_title . $title . $after_title;
$output .= $before_title . cortar_titulo( $title ) . $after_title;
$title = cortar_titulo(....
<code>
como estaba y llama a la función aquí.
<code>
$output .= '
';
if ( $comments ) {
foreach ( (array) $comments as $comment) {
$output .= '
' . /* translators: comments widget: 1: comment author, 2: post link */ sprintf(_x('%2$s', 'widgets'), cortar_titulo( get_comment_author_link() ), 'comment_ID) ) . '">' . get_the_title($comment->comment_post_ID) . '') . '
';
}
}
$output .= '
';
1 a 23 de 23