Problema al agregar código para posts relacionados en single.php

  • Autor Autor itxel
  • Fecha de inicio Fecha de inicio
itxel

itxel

Delta
Verificación en dos pasos activada
Verificado por Whatsapp
Hola chic@s.

Antes de nada decir que no tengo muchos conocimientos en PHP pero soy buena aprendiendo. Veréis estoy adaptando una theme y tengo un problema a la hora de agregarle el siguiente código en los posts relacionados. Entonces, os voy a dejar el código que implemento y el single.php por si alguien me puede ayudar... a ver que hago mal para que desaparezcan los comentarios publicados y el form del comentario.

Gracias de antemano.

El código toma los posts relacionados desde las tags, pero al implementarlo me desaparece todo lo relacionado con los comentarios.

PHP:
<div class="cuerpo-izquierda-titulo-capitulos">
<div class="clm">
<h3 class="title">Relacionados:</h3><br />
			  <div id="lcmain"><ul id="lcholder"> <li class="lcc">
			  <?php  //for use in the loop, list 5 post titles related to first tag on current post
  $backup = $post;  // backup the current object
  $tags = wp_get_post_tags($post->ID);
  $tagIDs = array();
  if ($tags) {
    $tagcount = count($tags);
    for ($i = 0; $i < $tagcount; $i++) {
      $tagIDs[$i] = $tags[$i]->term_id;
    }
    $args=array(
      'tag__in' => $tagIDs,
      'post__not_in' => array($post->ID),
      'showposts'=>10,
      'caller_get_posts'=>1
    );
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <h3><li><a href="<?php the_permalink() ?>"  class="lcc" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></li></h3>
      <?php endwhile;
    } else { ?>
      <h2>No related posts found!</h2>
    <?php }
  }
  $post = $backup;  // copy it back
  wp_reset_query(); // to use the original query again
?>
			  </ul></div></div></div>

Y el código del single es este:

PHP:
<article id="post-<?php the_ID(); ?>" <?php post_class('single-view'); ?>>

<div class="entry-header">
	<h1 class="entry-title"><a href="<?php the_permalink(); ?>">
		<?php
			if ( the_title( '', '', false ) != '' ){
				echo the_title();
			}
			else {
				echo __('Untitled', 'asteroid');
			}
		?>
	</a></h1>
</div>

<!-- Widgets: Before Post -->
<?php if ( ( is_active_sidebar('widgets_before_post') ) && is_singular() ) : ?>
	<div id="widgets-wrap-before-post"><?php dynamic_sidebar('widgets_before_post'); ?></div>
<?php endif ; ?>

<!-- Date & Author -->
<div class="entry-meta-top">
	<?php edit_post_link( __('Edit This', 'asteroid') ); ?>
	<?php if (
		( asteroid_option('ast_single_date') == 1 && is_singular('post') ) ||
		( asteroid_option('ast_single_date') == 2 && is_page() ) ||
		( asteroid_option('ast_single_date') == 3 && is_singular(array( 'post', 'page' )) )
		) :
	?>
		<div class="entry-date"><?php the_date(); ?></div>
	<?php endif; ?>

	<?php if (
		( asteroid_option('ast_single_author') == 1 && is_singular('post') ) ||
		( asteroid_option('ast_single_author') == 2 && is_page() ) ||
		( asteroid_option('ast_single_author') == 3 && is_singular(array( 'post', 'page' )) )
		) :
	?>
		<div class="entry-author"><?php _e('Posted by', 'asteroid'); ?>&nbsp;<?php the_author_posts_link(); ?></div>
	<?php endif; ?>
</div>

<div class="entry-content">

	<!-- Widgets: Before Post Content -->
	<?php if ( ( is_active_sidebar('widgets_before_post_content') ) && is_singular() ) : ?>
		<div id="widgets-wrap-before-post-content"><?php dynamic_sidebar('widgets_before_post_content'); ?></div>
	<?php endif ; ?>

	<?php the_content(); ?>

	<!-- Widgets: After Post Content -->
	<?php if ( ( is_active_sidebar('widgets_after_post_content') ) && is_singular() ) : ?>
		<div id="widgets-wrap-after-post-content"><?php dynamic_sidebar('widgets_after_post_content'); ?></div>
	<?php endif ; ?>

	<?php wp_link_pages( array(
		'before'           => '<div class="page-nav">' . __('<span>Pages</span>', 'asteroid'),
		'after'            => '</div>',
		'link_before'      => '<span>',
		'link_after'       => '</span>',
		'next_or_number'   => 'number',
		'nextpagelink'     => __('Next page', 'asteroid'),
		'previouspagelink' => __('Previous page', 'asteroid'),
		'pagelink'         => '%',
		'echo'             => 1 )
		);
	?>

</div>

<div class="entry-meta-bottom">

	<?php if (
		( asteroid_option('ast_date_modified') == 1 && is_singular('post') ) ||
		( asteroid_option('ast_date_modified') == 2 && is_page() ) ||
		( asteroid_option('ast_date_modified') == 3 && is_singular(array( 'post', 'page' )) )
		) :
	?>
		<div class="updated"><?php _e('Updated:', 'asteroid'); ?>&nbsp;<?php the_modified_date(); ?>&nbsp;<?php _e('at', 'asteroid'); ?>&nbsp;<?php the_modified_time(); ?></div>
	<?php endif; ?>

	<div class="entry-tags"><?php the_tags(); ?></div>

	<?php if ( is_attachment() ) : ?>
		<div class="next-previous-attachment">
			<div class="previous-link"><?php previous_image_link(0,__('&laquo; Previous Image', 'asteroid')) ?></div>
			<div class="next-link"><?php next_image_link(0,__('Next Image &raquo;', 'asteroid')) ?></div>
		</div>
	<?php endif; ?>

	<!-- Widgets: After Post -->
	<?php if ( ( is_active_sidebar('widgets_after_post') ) && is_singular() ) : ?>
		<div id="widgets-wrap-after-post"><?php dynamic_sidebar('widgets_after_post'); ?></div>
	<?php endif ; ?>

	<?php if ( is_singular('post') || is_attachment() ) : ?>
		<div class="next-previous-post">
			<div class="previous-link"><?php previous_post_link('◀ %link'); ?></div>
			<div class="next-link"><?php next_post_link('%link ▶'); ?></div>
		</div>
	<?php endif; ?>
</div>

<?php if ( is_singular('post') && ( asteroid_option('ast_post_author_info_box') == 1 ) ) : ?>
	<div class="author-info-box">
		<h4 class="author-info-box-title"><?php _e('About the Author', 'asteroid'); ?></h4>
		<div class="author-info">
			<div class="author-avatar"><?php echo get_avatar( get_the_author_meta('ID'), 64 ); ?></div>
			<div class="author-description">
				<h4><?php echo get_the_author_link(); ?></h4>
				<?php echo get_the_author_meta('description') ; ?>
			</div>
		</div>
	</div>
<?php endif; ?>

<?php if (
	( asteroid_option('ast_post_comments') == 1 && is_singular('post') ) ||
	( asteroid_option('ast_page_comments') == 1 && is_page() )
	) :
?>
	<?php comments_template(); ?>
<?php endif; ?>

</article>

Y así quedaría el código completo

PHP:
<article id="post-<?php the_ID(); ?>" <?php post_class('single-view'); ?>>

<div class="entry-header">
	<h1 class="entry-title"><a href="<?php the_permalink(); ?>">
		<?php
			if ( the_title( '', '', false ) != '' ){
				echo the_title();
			}
			else {
				echo __('Untitled', 'asteroid');
			}
		?>
	</a></h1>
</div>

<!-- Widgets: Before Post -->
<?php if ( ( is_active_sidebar('widgets_before_post') ) && is_singular() ) : ?>
	<div id="widgets-wrap-before-post"><?php dynamic_sidebar('widgets_before_post'); ?></div>
<?php endif ; ?>

<!-- Date & Author -->
<div class="entry-meta-top">
	<?php edit_post_link( __('Edit This', 'asteroid') ); ?>
	<?php if (
		( asteroid_option('ast_single_date') == 1 && is_singular('post') ) ||
		( asteroid_option('ast_single_date') == 2 && is_page() ) ||
		( asteroid_option('ast_single_date') == 3 && is_singular(array( 'post', 'page' )) )
		) :
	?>
		<div class="entry-date"><?php the_date(); ?></div>
	<?php endif; ?>

	<?php if (
		( asteroid_option('ast_single_author') == 1 && is_singular('post') ) ||
		( asteroid_option('ast_single_author') == 2 && is_page() ) ||
		( asteroid_option('ast_single_author') == 3 && is_singular(array( 'post', 'page' )) )
		) :
	?>
		<div class="entry-author"><?php _e('Posted by', 'asteroid'); ?>&nbsp;<?php the_author_posts_link(); ?></div>
	<?php endif; ?>
</div>

<div class="entry-content">

	<!-- Widgets: Before Post Content -->
	<?php if ( ( is_active_sidebar('widgets_before_post_content') ) && is_singular() ) : ?>
		<div id="widgets-wrap-before-post-content"><?php dynamic_sidebar('widgets_before_post_content'); ?></div>
	<?php endif ; ?>

	<?php the_content(); ?>
<div class="cuerpo-izquierda-titulo-capitulos">
<div class="clm">
<h3 class="title">Relacionados:</h3><br />
			  <div id="lcmain"><ul id="lcholder"> <li class="lcc">
			  <?php  //for use in the loop, list 5 post titles related to first tag on current post
  $backup = $post;  // backup the current object
  $tags = wp_get_post_tags($post->ID);
  $tagIDs = array();
  if ($tags) {
    $tagcount = count($tags);
    for ($i = 0; $i < $tagcount; $i++) {
      $tagIDs[$i] = $tags[$i]->term_id;
    }
    $args=array(
      'tag__in' => $tagIDs,
      'post__not_in' => array($post->ID),
      'showposts'=>10,
      'caller_get_posts'=>1
    );
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <h3><li><a href="<?php the_permalink() ?>"  class="lcc" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></li></h3>
      <?php endwhile;
    } else { ?>
      <h2>No related posts found!</h2>
    <?php }
  }
  $post = $backup;  // copy it back
  wp_reset_query(); // to use the original query again
?>
			  </ul></div></div></div>

	<!-- Widgets: After Post Content -->
	<?php if ( ( is_active_sidebar('widgets_after_post_content') ) && is_singular() ) : ?>
		<div id="widgets-wrap-after-post-content"><?php dynamic_sidebar('widgets_after_post_content'); ?></div>
	<?php endif ; ?>

	<?php wp_link_pages( array(
		'before'           => '<div class="page-nav">' . __('<span>Pages</span>', 'asteroid'),
		'after'            => '</div>',
		'link_before'      => '<span>',
		'link_after'       => '</span>',
		'next_or_number'   => 'number',
		'nextpagelink'     => __('Next page', 'asteroid'),
		'previouspagelink' => __('Previous page', 'asteroid'),
		'pagelink'         => '%',
		'echo'             => 1 )
		);
	?>

</div>

<div class="entry-meta-bottom">

	<?php if (
		( asteroid_option('ast_date_modified') == 1 && is_singular('post') ) ||
		( asteroid_option('ast_date_modified') == 2 && is_page() ) ||
		( asteroid_option('ast_date_modified') == 3 && is_singular(array( 'post', 'page' )) )
		) :
	?>
		<div class="updated"><?php _e('Updated:', 'asteroid'); ?>&nbsp;<?php the_modified_date(); ?>&nbsp;<?php _e('at', 'asteroid'); ?>&nbsp;<?php the_modified_time(); ?></div>
	<?php endif; ?>

	<div class="entry-tags"><?php the_tags(); ?></div>

	<?php if ( is_attachment() ) : ?>
		<div class="next-previous-attachment">
			<div class="previous-link"><?php previous_image_link(0,__('&laquo; Previous Image', 'asteroid')) ?></div>
			<div class="next-link"><?php next_image_link(0,__('Next Image &raquo;', 'asteroid')) ?></div>
		</div>
	<?php endif; ?>

	<!-- Widgets: After Post -->
	<?php if ( ( is_active_sidebar('widgets_after_post') ) && is_singular() ) : ?>
		<div id="widgets-wrap-after-post"><?php dynamic_sidebar('widgets_after_post'); ?></div>
	<?php endif ; ?>

	<?php if ( is_singular('post') || is_attachment() ) : ?>
		<div class="next-previous-post">
			<div class="previous-link"><?php previous_post_link('◀ %link'); ?></div>
			<div class="next-link"><?php next_post_link('%link ▶'); ?></div>
		</div>
	<?php endif; ?>
</div>

<?php if ( is_singular('post') && ( asteroid_option('ast_post_author_info_box') == 1 ) ) : ?>
	<div class="author-info-box">
		<h4 class="author-info-box-title"><?php _e('About the Author', 'asteroid'); ?></h4>
		<div class="author-info">
			<div class="author-avatar"><?php echo get_avatar( get_the_author_meta('ID'), 64 ); ?></div>
			<div class="author-description">
				<h4><?php echo get_the_author_link(); ?></h4>
				<?php echo get_the_author_meta('description') ; ?>
			</div>
		</div>
	</div>
<?php endif; ?>

<?php if (
	( asteroid_option('ast_post_comments') == 1 && is_singular('post') ) ||
	( asteroid_option('ast_page_comments') == 1 && is_page() )
	) :
?>
	<?php comments_template(); ?>
<?php endif; ?>

</article>
 
itxel,

¿Cuando eliminas el código que agregaste al single.php aparecen los comentarios?
¿Cuál es tu web para visitarla?

Estaré atento a tu respuesta.

Saludos
 
itxel,

¿Cuando eliminas el código que agregaste al single.php aparecen los comentarios?
¿Cuál es tu web para visitarla?

Estaré atento a tu respuesta.

Saludos

Gracias por la respuesta Tonberry.

Síp, en cuanto elimino el código aparecen de nuevo los comentarios sin ningún problema.

Tengo el theme instalado en
...

Saludos y de nuevo muchas gracias
 
Última edición:
Atrás
Arriba