@zeaovede

Как перенести comments.php из одной темы в другую?

Решил перенести комментарии из ранее используемой темы в актуальную тему на wordpress. Экспортировал страницу с комментариями старой темы и импортировал в новую тему. С этим проблем никаких. Затем скопировал содержимое comment.php и вставил в comments.php новой темы. Теперь страница с комментариями новой темы не загружается.
Для сравнения
comments.php ранее используемой темы

spoiler
<?php if (comments_open()) : ?>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" />
<style>
#system #comments .comment-head .avatar {
//border: 1px solid #ccc;
border-radius: 50%;
}
a.permalink {
color: #999;
}
a.permalink:hover {
color: #469bdb;
}
.commentItem.rem {
display: none;
}
</style>
	<section id="comments">
		<?php if (have_comments()) : ?>
			<?php
				$classes = array("level1");
			
				if (get_option('comment_registration') && !is_user_logged_in()) {
					$classes[] = "no-response";
				}
				
				if (get_option('thread_comments')) {
					$classes[] = "nested";
				}
			
			?>

			<ul class="commentsList <?php echo implode(" ", $classes);?>">
			<?php 
				
				// single comment
				$GLOBALS['comment_count'] = 0;
				
				function mytheme_comment($comment, $args, $depth) {
					global $user_identity;
					
					static $cnt = 0;
					
					$GLOBALS['comment_count']++;
					
					$GLOBALS['comment'] = $comment;
					$warp = Warp::getInstance();
					
					$_GET['replytocom'] = get_comment_ID();
					?>
					<li class="commentItem <?= $cnt++ < 15 ? '' : 'rem' ?>">
					<!--li class="commentItem"-->
						<article id="comment-<?php comment_ID(); ?>" class="comment <?php echo ($comment->user_id > 0) ? 'comment-byadmin' : '';?>">
					 
							
							
							<div class="comment-body" style="padding: 20px 20px; background-color: #f8f8f8; border: 1px solid #eaeaea; color: #666;">
							
								<p class="comment-dody"><div class="content" style="font-size: 16px;"><?php comment_text(); ?></div>
								
								<?php if (comments_open()) : ?>


<p class="ReviewBox-Header"><p class="ReviewBox-small">
								
<?php endif; ?>
								
							</div>
							<header class="comment-head" style="background-color: transparent; border: 0px;">
								
								
								<?php echo get_avatar($comment, $size='50', get_bloginfo('template_url').'/images/default_avatar.png'); ?>
								
								<h4 class="author" style="font-size: 16px; font-weight: normal; margin-top: 0; color: #999999; padding: 3.5px;"><i class="fa fa-user"></i>
  <?php echo get_comment_author_link(); ?></h4>
							
								<p class="meta" style="font-size: 16px; color: #999999;">
									<i class="fa fa-calendar"></i> <time datetime="<?php echo get_comment_date('Y-m-d'); ?>" pubdate><?php printf(__('%1$s в %2$s', 'warp'), get_comment_date(), get_comment_time()) ?></time>
									
									<?php edit_comment_link(__('Edit'),' ','') ?>
								</p>
							
							</header>
						</article>
					<?php
					unset($_GET['replytocom']);
					
					// </li> is rendered by system
				}

				if (empty($_SERVER['HTTP_X_REQUESTED_WITH']))
				{
					wp_list_comments('type=all&page=0&per_page=1000000&callback=mytheme_comment');
					//echo "COUNT: " . print_r(get_comment_count(the_ID()), true);
					//exit;
				}
				else 
				{
					wp_list_comments('type=all&callback=mytheme_comment');
				}
			?>
			</ul>
			
<script>
//var comment_count = <?= $GLOBALS['comment_count'] ?>;
var els = document.querySelectorAll('.commentItem.rem');
for (var i = 0; i < els.length; i++) els[i].remove();
window.commentLink = 'https://ggraft.ru/reviews/comment-page-<?= (int)(($GLOBALS['comment_count'] / 15) - 2) ?>/#comments';
$(document).ready(function() {
	$('.more-comments').bind('DOMSubtreeModified', function() {
		var that = this;
		setTimeout(function() {
			var count = that.querySelector('span').innerText * 1;
			console.log('count', count);
			if (count <= 0) {
				that.remove();
			}
		}, 150);
	});
});
</script>
			
<div style="display:none;">
		<?php echo $this->render("_pagination", array("type"=>"comments")); ?>
		</div>
<?php if (get_comments_number() > 0) : ?>
		 <p class="text"><?php comments_open() ? printf(__('', 'warp'), get_comments_number()) : _e('Comments are closed', 'warp'); ?></p>
	   
		<?php endif; ?>
<div class = "center">

  <a href="#" class="more-comments" data-comments-number="<?=get_comments_number();?>">Загрузить ещё<span class="counter"><?=get_comments_number();?></span>
  <div class="scroller-status">
		<div class="loader-ellips">
			<div class="loader-ellips__dot"></div>
			<div class="loader-ellips__dot"></div>
			<div class="loader-ellips__dot"></div>
			<div class="loader-ellips__dot"></div>
		</div>
	</div>
  </a>
</div>
	<?php endif; ?>

		<div id="respond">
			<br /><br />
			<a name="vniz"></a>
			<h3 style="font-family: 'Roboto', sans-serif; font-weight: 700; font-size: 26px;"><?php comment_form_title(__('Оставить отзыв', 'warp')); ?></h3>
			<br />
			Ваш e-mail не будет опубликован. Обязательные поля помечены <span style="color:red;">*</span>
			<br />
		
			<?php if (get_option('comment_registration') && !is_user_logged_in()) : ?>
			<p class="user"><?php printf(__('You must be <a href="%s">logged in</a> to post a comment.', 'warp'), wp_login_url(get_permalink())); ?></p>
			<?php else : ?>			
			<?php endif; ?>
			
		</div>

	</section>
	
	
	<script type="text/javascript">
			
		jQuery(function($) {
			
			var respond = $("#respond");
			
			$("p.reply > a").bind("click", function(){
				
				var id = $(this).attr('rel');
				
				respond.find(".comment-cancelReply:first").remove();
				
				var cancel = $('<a><?php echo __("Cancel");?></a>').addClass('comment-cancelReply').attr('href', "#respond").bind("click", function(){
					respond.find(".comment-cancelReply:first").remove();
					respond.appendTo($('#comments')).find("[name=comment_parent]").val(0);
					return false;
				}).appendTo(respond.find(".actions:first"));
				
				respond.find("[name=comment_parent]").val(id);
				respond.appendTo($("#comment-"+id));
				
				return false;
				
			})
			
			$('form.short input[placeholder]').placeholder();
		});
			
	</script>

<?php endif;

comments.php актуальной темы

spoiler
<?php
/**
 * The template for displaying comments
 *
 * This is the template that displays the area of the page that contains both the current comments
 * and the comment form.
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package eloboost
 */

/*
 * If the current post is protected by a password and
 * the visitor has not yet entered the password we will
 * return early without loading the comments.
 */
if ( post_password_required() ) {
	return;
}
?>

<div id="comments" class="comments-area">

	<?php
	// You can start editing here -- including this comment!
	if ( have_comments() ) :
		?>
		<h2 class="comments-title">
			<?php
			$eloboost_comment_count = get_comments_number();
			if ( '1' === $eloboost_comment_count ) {
				printf(
					/* translators: 1: title. */
					esc_html__( 'One thought on &ldquo;%1$s&rdquo;', 'eloboost' ),
					'<span>' . wp_kses_post( get_the_title() ) . '</span>'
				);
			} else {
				printf( 
					/* translators: 1: comment count number, 2: title. */
					esc_html( _nx( '%1$s thought on &ldquo;%2$s&rdquo;', '%1$s thoughts on &ldquo;%2$s&rdquo;', $eloboost_comment_count, 'comments title', 'eloboost' ) ),
					number_format_i18n( $eloboost_comment_count ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
					'<span>' . wp_kses_post( get_the_title() ) . '</span>'
				);
			}
			?>
		</h2><!-- .comments-title -->

		<?php the_comments_navigation(); ?>

		<ol class="comment-list">
	
			
		</ol><!-- .comment-list -->

		<?php
		the_comments_navigation();

		// If comments are closed and there are comments, let's leave a little note, shall we?
		if ( ! comments_open() ) :
			?>
			<p class="no-comments"><?php esc_html_e( 'Comments are closed.', 'eloboost' ); ?></p>
			<?php
		endif;

	endif; // Check for have_comments().

	comment_form();
	?>

</div><!-- #comments -->


Помогите, пожалуйста, разобраться
  • Вопрос задан
  • 46 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы