D
D
dvakarandasha2018-06-29 14:51:14
WordPress
dvakarandasha, 2018-06-29 14:51:14

Wordpress loading posts ajax duplication, because of what?

There is a site on Wordpress - https://www.lavitanostra.net/
Under the posts by clicking on the "show more" button, instead of displaying the posts, it gives the Cannot redeclare error.
It looks like the code from the main post loading page is re-launching the theme's function.php.
Here is the code for the main page that displays the posts and the button.
Empirically, I found out that the data-theme="<?php echo get_template(); ?>" line is to blame, which re-calls the theme files and function.php, including
Maybe someone knows how to fix this in Wordpress?

<main class="content<?php echo $class_home_content; ?>">
    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;	
    $args = array(
      'post_type' => 'post',
      'posts_per_page' => $posts_per_home,
      'paged' => $paged,
    );
    $loop = new WP_Query($args);
    if ($loop->have_posts()) { 
      ?>
      <div class="title">Свежие публикации</div>
      <div class="posts posts_home ajax_pagination">
        <?php 
        while ($loop->have_posts()) { $loop->the_post();
          require 'loop.php';
        } ?>
      </div>
      <?php
     	if ( $loop->max_num_pages > 1 ) { 
        ?>
        <div class="more"
          data-newposts="1"
          data-items="<?php echo $posts_per_home; ?>"
          data-offset="<?php echo $posts_per_home; ?>"
          data-theme="<?php echo get_template(); ?>"
          data-loading="Загрузка..."><span>Показать ещё</span>
        </div>
        <?php
      } 
    } wp_reset_query(); 

    $args = array(
      'posts_per_page' => 15,
      'meta_key' => 'post_views_count',
      'orderby' => 'meta_value_num',
      'meta_query' => 
      array(
          array(
              'key'     => 'slider',
              'compare' => 'NOT EXISTS'
          )
      ),
    );
    $loop = new WP_Query($args); 
    if ($loop->have_posts()) { 
      
      if ($disable_sidebar_homepage) echo '<div class="top-widgets-wrap"><div class="top-posts-wrap_remove-sidebar">'; ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MrTimon, 2018-06-29
@MrTimon

You have either rewritten the get_template function or you have done something wrong in the template filter. The get_template function should return the name of the current theme's directory, only fetching the option from wp_options.
I can advise you to replace get_template() with get_option( 'template' ).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question