Устранить ошибку плавной загрузки контента wordpress?

Для вывода контента используя плавную подгрузку контента.
function misha_loadmore_ajax_handler(){
 
	// prepare our arguments for the query
	$args = json_decode( stripslashes( $_POST['query'] ), true );
	$args['paged'] = $_POST['page'] + 1; // we need next page to be loaded
	$args['post_status'] = 'publish';
 
	// it is always better to use WP_Query but not here
	query_posts( $args );
 
	if( have_posts() ) :
 
		// run the loop
		while( have_posts() ): the_post();
 
			// look into your theme code how the posts are inserted, but you can use your own HTML of course
			// do you remember? - my example is adapted for Twenty Seventeen theme
			get_template_part( 'content', get_post_format() );
			// for the test purposes comment the line above and uncomment the below one
			// the_title();
 
 
		endwhile;
 
	endif;
	die; // here we exit the script and even no wp_reset_query() required!
}


Но для дочерних рубрик использую отдельный шаблон кнотента (content-daughter). Делается это через код:
function portfolio_page_template( $template ) {
	if( ! is_category() ) return $template;

	$current_cat = get_queried_object();

	if( $current_cat->parent ){
		if ( $new_template = locate_template( array( 'category-daughter.php' ) ) )
			$template =  $new_template ;
	}

	return $template;
}

add_filter( 'template_include', 'portfolio_page_template', 99 );


При таком подходе получается глюк: первый экран отображается как надо, а дальше, когда включается подгрузка контента, то она берет по умолчанию шаблон content и игнорирует content-daughter в дочерних рубриках. Помогите, пожалуйста, совместить эти два кода, чтобы устранить данный глюк.
  • Вопрос задан
  • 54 просмотра
Пригласить эксперта
Ответы на вопрос 1
скорее всего не правильно отрабатывает код:
get_template_part( 'content', get_post_format() );

попробуйте строго задать шаблон
get_template_part( 'content', 'daughter' );

если сработало, разбирайтесь, что возвращает функция get_post_format() в вашем случае, либо пишите условие для подключения файла шаблона, в зависимости от категории.
Ответ написан
Ваш ответ на вопрос

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

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