Foros del Web » Creando para Internet » Sistemas de gestión de contenidos » WordPress »

Modificar la fecha de los comentarios

Estas en el tema de Modificar la fecha de los comentarios en el foro de WordPress en Foros del Web. Saludos de nuevo, me enfrento a otro apasionante dilema en el sistema WordPress, y es que tengo unos comentarios con la siguiente estructura en la ...
  #1 (permalink)  
Antiguo 04/11/2011, 17:09
Avatar de ManuelAlejandro  
Fecha de Ingreso: noviembre-2009
Ubicación: Alicante
Mensajes: 87
Antigüedad: 14 años, 5 meses
Puntos: 6
Busqueda Modificar la fecha de los comentarios

Saludos de nuevo, me enfrento a otro apasionante dilema en el sistema WordPress, y es que tengo unos comentarios con la siguiente estructura en la fecha:

21 febrero, 2011 a las 10:18

Y me gustaría dejar el día, el mes y el año, y eliminar el a las x hora.

El código de comments.php es este pero no logro encontrar el trozo correspondiente:

Código:
<?php

// Do not delete these lines
	if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
		die ('Please do not load this page directly. Thanks!');

	if ( post_password_required() ) { ?>

<p class="nocomments">Password protected.</p>
<?php
		return;
	}
?>
<!-- You can start editing here. -->
<div class="comments-box"> <a name="comments" id="comments"></a>
  <?php if ( have_comments() ) : ?>
  <h2>
    <?php comments_number('', '1 Opini&oacute;n', '% Opiniones' );?>
  </h2>
  <ol class="commentlist">
    <?php wp_list_comments('type=comment&avatar_size=48'); ?>
  </ol>
  <div class="pagenavi">
    <div class="nextprev left">
      <?php previous_comments_link() ?>
    </div>
    <div class=" nextprev right">
      <?php next_comments_link() ?>
    </div>
    <div class="clear"></div>
  </div>
  <?php else : // this is displayed if there are no comments so far ?>
  <?php if ('open' == $post->comment_status) : ?>
  <!-- If comments are open, but there are no comments. -->
  <?php else : // comments are closed ?>
  <!-- If comments are closed. -->
  <?php endif; ?>
  <?php endif; ?>
  <?php if ('open' == $post->comment_status) : ?>
  <div id="respond">
    <h2>Tu opini&oacute;n</h2>
    <div class="cancel-comment-reply"> <small>
      <?php cancel_comment_reply_link(); ?>
      </small> </div>
    <?php if ( get_option('comment_registration') && !$user_ID ) : ?>
    <p><?php print 'You must be'; ?> <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?redirect_to=<?php echo urlencode(get_permalink()); ?>"><?php print 'Logged in'; ?></a> <?php print 'to post comment'; ?>.</p>
    <?php else : ?>
    <form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
      <?php if ( $user_ID ) : ?>
      <p><?php print 'Logged as'; ?> <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>. <a href="<?php echo wp_logout_url(get_permalink()); ?>" title="Log out of this account"><?php print 'Log out'; ?> &raquo;</a></p>
      <?php else : ?>
      <p>
        <input class="author" type="text" value="tu nombre..." onclick="this.value='';" name="author" id="author" size="22" tabindex="1"/>
        <label for="author"><small>
          <?php if ($req) echo "(requerido)"; ?>
          </small></label>
      </p>
      <p>
        <input class="email" type="text" value="tu email..." onclick="this.value='';" name="email" id="email" size="22" tabindex="2"/>
        <label for="email"><small>(no ser&aacute; publicado)
          <?php if ($req) echo " (requerido)"; ?>
          </small></label>
      </p>
      <p>
        <input class="url" type="text" value="tu web..." onclick="this.value='';" name="url" id="url" size="22" tabindex="3"/>
        <label for="url"><small>(opcional)</small></label>
      </p>
      <?php endif; ?>
      <!--<p><small><strong>XHTML:</strong> You can use these tags: <code><?php echo allowed_tags(); ?></code></small></p>-->
      <p>
        <textarea name="comment" id="comment" tabindex="4"></textarea>
      </p>
      <p>
        <input class="submit" name="submit" type="submit" id="submit" tabindex="5" value="Opina" />
        <?php comment_id_fields(); ?>
      </p>
      <?php do_action('comment_form', $post->ID); ?>
    </form>
    <?php endif; // If registration required and not logged in ?>
  </div>
  <?php endif; // if you delete this the sky will fall on your head ?>
</div>
  #2 (permalink)  
Antiguo 04/11/2011, 18:30
Avatar de carlos_belisario
Colaborador
 
Fecha de Ingreso: abril-2010
Ubicación: Venezuela Maracay Aragua
Mensajes: 3.156
Antigüedad: 14 años
Puntos: 461
Respuesta: Modificar la fecha de los comentarios

podrías crearte una funcion para llamarla en el calback como lo hace twenty
Código PHP:
Ver original
  1. wp_list_comments( array( 'callback' => 'twentyeleven_comment' ) );
puedes ver la funcion en el archivo function.php del tema twenty que es el que trae por defecto wordpress, y modificas esta línea
Código PHP:
Ver original
  1. sprintf( __( '%1$s at %2$s', 'twentyeleven' ), get_comment_date(), get_comment_time())
y lo colocas así
Código PHP:
Ver original
  1. sprintf(__('%1$s', 'twentyeleven'),get_comment_date())
de tal manera que no te traiga la hora sino únicamente el día, saludos
__________________
aprende d tus errores e incrementa tu conocimientos
it's not a bug, it's an undocumented feature By @David
php the right way
  #3 (permalink)  
Antiguo 05/11/2011, 08:14
Avatar de ManuelAlejandro  
Fecha de Ingreso: noviembre-2009
Ubicación: Alicante
Mensajes: 87
Antigüedad: 14 años, 5 meses
Puntos: 6
Respuesta: Modificar la fecha de los comentarios

Gracias Carlos, encontré ese trozo de código en el theme de twenty pero nada parecido en el que tengo ahora mismo, imagino que como dices tengo que crear yo mismo la función, aunque estoy probando y me estoy montando un poco de cacao, mi código de function es:

Código:
<?php

include("includes/theme-options.php");

# Sidebar
if (function_exists('register_sidebar'))
{
	register_sidebar(array(
		'name'			=> 'Home/Page Left',
	    'before_widget'	=> '',
	    'after_widget'	=> '</div>',
	    'before_title'	=> '<h3>',
	    'after_title'	=> '</h3><div class="clear"></div><div class="box">',
	));		
	
    register_sidebar(array(
		'name'			=> 'Home Right #Full Width',
        'before_widget'	=> '',
        'after_widget'	=> '</div>',
        'before_title'	=> '<h3>',
        'after_title'	=> '</h3><div class="clear"></div><div class="box">',
    ));		
	
    register_sidebar(array(
		'name'			=> 'Home Right #Left',
        'before_widget'	=> '',
        'after_widget'	=> '</div>',
        'before_title'	=> '<h3>',
        'after_title'	=> '</h3><div class="clear"></div><div class="box">',
    ));	
	
    register_sidebar(array(
		'name'			=> 'Home Right #Right',
        'before_widget'	=> '',
        'after_widget'	=> '</div>',
        'before_title'	=> '<h3>',
        'after_title'	=> '</h3><div class="clear"></div><div class="box">',
    ));		
		
    register_sidebar(array(
		'name'			=> 'Page Right',
        'before_widget'	=> '',
        'after_widget'	=> '</div>',
        'before_title'	=> '<h3>',
        'after_title'	=> '</h3><div class="clear"></div><div class="box">',
    ));	
    
    register_sidebar(array(
    	'name'			=> 'Footer',
        'before_widget'	=> '',
        'after_widget'	=> '</div>',
        'before_title'	=> '<div class="footerwidget left"><h3>',
        'after_title'	=> '</h3>',
    ));	
}

# Limit Post
function tj_content_limit($max_char, $more_link_text = '', $stripteaser = 0, $more_file = '') {
    $content = get_the_content($more_link_text, $stripteaser, $more_file);
    $content = apply_filters('the_content', $content);
    $content = str_replace(']]>', ']]&gt;', $content);
    $content = strip_tags($content);

   if (strlen($_GET['p']) > 0) {
      echo "";
      echo $content;
      echo "...";
   }
   else if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
        $content = substr($content, 0, $espacio);
        $content = $content;
        echo "";
        echo $content;
        echo "...";
   }
   else {
      echo "";
      echo $content;
   }
}

# Turn a category ID to a Name
function cat_id_to_name($id) {
	foreach((array)(get_categories()) as $category) {
    	if ($id == $category->cat_ID) { return $category->cat_name; break; }
	}
}

# Get image attachment (sizes: thumbnail, medium, full)
function get_thumbnail($postid=0, $size='full') {
	if ($postid<1) 
	$postid = get_the_ID();
	$thumb = get_post_meta($postid, "thumb", TRUE); // Declare the custom field for the image
	if ($thumb != null or $thumb != '') {
		echo $thumb; 
	}
	elseif ($images = get_children(array(
		'post_parent' => $postid,
		'post_type' => 'attachment',
		'numberposts' => '1',
		'post_mime_type' => 'image', )))
		foreach($images as $image) {
			$thumbnail=wp_get_attachment_image_src($image->ID, $size);
			?>
<?php echo $thumbnail[0]; ?>
<?php
		}
	else {
		echo get_bloginfo ( 'stylesheet_directory' );
		echo '/images/image-pending.gif';
	}
	
}

# Automatically display/resize thumbnail
function tj_thumbnail($width, $height) {
?>

<a href="<?php the_permalink() ?>" rel="bookmark"> <img src="<?php bloginfo('template_directory'); ?>/includes/timthumb.php?src=<?php get_thumbnail($post->ID, 'full'); ?>&amp;h=<?php echo get_theme_mod($height); ?>&amp;w=<?php echo get_theme_mod($width); ?>&amp;zc=1" alt="<?php the_title(); ?>" /> </a>
<?php
}

# Breadcrumb
function the_breadcrumb() {
	if (!is_home()) {
		echo 'Est&aacute;s aqu&iacute;: ';
		if (is_category() || is_single()) {
			single_cat_title();
			if (is_single()) {
			the_category(', ');
				echo " &raquo; ";
				the_title();
			}
		} elseif (is_page()) {
			echo the_title();
		}
		  elseif (is_tag()) {
			echo 'Posts tagged with "'; 
			single_tag_title();
			echo '"'; }
		elseif (is_day()) {echo "Archive for "; the_time(' F jS, Y');}
		elseif (is_month()) {echo "Archive for "; the_time(' F, Y');}
		elseif (is_year()) {echo "Archive for "; the_time(' Y');}
		elseif (is_author()) {echo "Author Archive";}
		elseif (isset($_GET['paged']) && !empty($_GET['paged'])) {echo "Blog Archives";}
		elseif (is_search()) {echo "Resultados de b&uacute;squeda";}
	}
}


#Get recent comments
function tj_recent_comments($no_comments = 5, $comment_lenth = 5, $before = '<li>', $after = '</li>', $show_pass_post = false, $comment_style = 1, $hide_pingbacks_trackbacks = false) {
	global $wpdb;
	$most_recent_comments = wp_cache_get('most_recent_comments');
	
	if ( false === $most_recent_comments ) {
		$request = "SELECT ID, comment_ID, comment_content, comment_author, comment_author_url, post_title FROM $wpdb->comments LEFT JOIN $wpdb->posts ON $wpdb->posts.ID=$wpdb->comments.comment_post_ID WHERE post_status IN ('publish','static') ";
		if( !$show_pass_post ) $request .= "AND post_password ='' ";
		if ( $hide_pingbacks_trackbacks ) $request .= "AND comment_type='' ";
		$request .= "AND comment_approved = '1' ORDER BY comment_ID DESC LIMIT $no_comments";

		$comments = $wpdb->get_results($request);
	
		$output = '';

		if ( $comments ) {
			$idx = 0;
			foreach ($comments as $comment) {
				$comment_author = stripslashes($comment->comment_author);
				if ($comment_author == "")
					$comment_author = "anonymous"; 
				$comment_content = strip_tags($comment->comment_content);
				$comment_content = stripslashes($comment_content);
				$words = split(" ", $comment_content); 
				$comment_excerpt = join(" ", array_slice($words, 0, $comment_lenth));
				$permalink = get_permalink($comment->ID) . "#comment-" . $comment->comment_ID;
				
				if ( 1 == $comment_style ) {
					$post_title = stripslashes($comment->post_title);
					$post_id= stripslashes($comment->post_id);
					$url = $comment->comment_author_url;
					$idx++;
					if ( 1 == $idx % 2 )
						$before = "<li>";
					else
						$before = "<li>";
					$output .= $before . "<a href='$permalink'>$comment_author</a>" . ' on <a href="' . get_permalink($comment->ID) . '">' . $post_title . '</a>' . $after;
				} else {
					$idx++;
					if ( 1 == $idx % 2 )
						$before = "<li class=''>";
					else
						$before = "<li class=''>";
		
					$output .= $before . '<strong>' . $comment_author . ':</strong> <a href="' . $permalink;
					$output .= '" title="View the entire comment by ' . $comment_author.'">' . $comment_excerpt.'</a>' . $after;
				}
			}

			$output = convert_smilies($output);
		} else {
			$output .= $before . "None found" . $after;
		}

		$most_recent_comments = $output;
		wp_cache_set('most_recent_comments', $most_recent_comments);
	}

	echo $most_recent_comments;
	}

# Get popular posts by comments count
function tj_popular_posts($no_posts = 5, $before = '<li>', $after = '</li>', $show_pass_post = false, $duration='') {
global $wpdb;
$request = "SELECT ID, post_title, COUNT($wpdb->comments.comment_post_ID) AS 'comment_count' FROM $wpdb->posts, $wpdb->comments";
$request .= " WHERE comment_approved = '1' AND $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status = 'publish'";
if(!$show_pass_post) $request .= " AND post_password =''";
if($duration !="") { $request .= " AND DATE_SUB(CURDATE(),INTERVAL ".$duration." DAY) < post_date ";
}
$request .= " GROUP BY $wpdb->comments.comment_post_ID ORDER BY comment_count DESC LIMIT $no_posts";
$posts = $wpdb->get_results($request);
$output = '';
if ($posts) {
foreach ($posts as $post) {
$post_title = stripslashes($post->post_title);
$comment_count = $post->comment_count;
$permalink = get_permalink($post->ID);
$output .= $before . '<a href="' . $permalink . '" title="' . $post_title.'">' . $post_title . '</a>' . $after;
}
} else {
$output .= $before . "None found" . $after;
}
echo $output;
}

add_post_type_support('page', 'excerpt');

?>
A ver si alguien puede orientarme un poco, muchas gracias por todo : )
  #4 (permalink)  
Antiguo 05/11/2011, 09:10
Avatar de carlos_belisario
Colaborador
 
Fecha de Ingreso: abril-2010
Ubicación: Venezuela Maracay Aragua
Mensajes: 3.156
Antigüedad: 14 años
Puntos: 461
Respuesta: Modificar la fecha de los comentarios

que versión de wordpress tienes?? la ultima que trae twenty eleven?? de ahí saque la función y la acomode a lo que tu pedías, si puedes descárgate la ultima versión para que veas la plantilla twnety eleven que es de donde saque la función, la cual esta en el archivo functión y se llama twentyeleven_comment, revisa y nos comentas
__________________
aprende d tus errores e incrementa tu conocimientos
it's not a bug, it's an undocumented feature By @David
php the right way

Etiquetas: comentarios, fecha, modificar
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 17:51.