@ruslan111192

Можно выводить форму комментария для каждой записи загруженного ajax WordPress?

Здравствуйте!
Можно как то подгружать форму комментариев для каждой записи подгруженной ajax.
У меня сейчас подгружено к первой записи форма. А вот во второй просто ссылка и при клике на которую переносить к первой записи.
Может есть плагин, можете что то посоветовать пожалуйста?

Вот функция подтягивания старых записей
function centil_infinite_scroll($pid){
    if (is_single()) { ?>
      <script type="text/javascript" >
        jQuery(document).ready(function($) {

          $(window).scroll(function() {
            var footerPos = $('footer').last().position().top;
            var pos = $(window).scrollTop();

          
            if (pos+(screen.height*1) > footerPos) {
              if ($(".centil-infinite-scroll").first().hasClass('working')) {
                return false;
              } else {
                $(".centil-infinite-scroll").first().addClass('working');
              }

              var centilPreviousPostId = $(".centil-infinite-scroll").first().text();
              var data = {
                'action': 'centil_is',
                'centilPreviousPostId': centilPreviousPostId
              };

              
              jQuery.post('<?php echo admin_url("admin-ajax.php"); ?>', data, function(response) {
                $(".centil-infinite-scroll").first().replaceWith(response);
              }, 'html');
            }

           
            var currUrl = $(".centil-post-header").first().attr("url");
            var currTitle = $(".centil-post-header").first().attr("title");

            if ($(".centil-post-header").length > 1 && history.pushState) {
              for (var i=0; i<$(".centil-post-header").length; i++) {
                if (pos+(screen.height/2) >= $(".centil-post-header").eq(i).next().position().top) {
                  currUrl = $(".centil-post-header").eq(i).attr("url");
                  currTitle = $(".centil-post-header").eq(i).attr("title");
                }
              }
            }
            if (location.href != currUrl) {
              history.pushState({}, currTitle, currUrl);
            }
          });
        });
      </script>

    <?php }
  }
add_action( 'wp_head', 'centil_infinite_scroll' );

  function centil_infinite_scroll_callback() {

    if (isset($_POST['centilPreviousPostId']) && $_POST['centilPreviousPostId']) {
      
      $the_query = new WP_Query(array('p'=>$_POST['centilPreviousPostId']));

     
      if ( $the_query->have_posts() ) {
        while ( $the_query->have_posts() ) {
          $the_query->the_post();
          get_template_part( 'template-parts/content-news-infinity', get_post_type() ); 
			
        }
      }
      
      wp_reset_postdata();
   		
    }

    wp_die();
  }

  add_action( 'wp_ajax_centil_is', 'centil_infinite_scroll_callback' );
  add_action( 'wp_ajax_nopriv_centil_is', 'centil_infinite_scroll_callback' );
  • Вопрос задан
  • 53 просмотра
Пригласить эксперта
Ваш ответ на вопрос

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

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