2017-02-10 4 views
1

У меня есть этот настраиваемый шаблон в Wordpress, который включает в себя скрипт, который разбивает поля ACF. Вот исходный код:ACF Pagination не работает, когда присутствует__состояние

<?php get_header(); ?> 

<div class="container"> 
    <div class="row"> 
     <div class="col-xs-12"> 
      <h1 class="pagetitle"><?php the_title(); ?></h1> 
     </div> <!-- col --> 
    </div> <!-- row --> 
</div> <!-- container --> 

<?php 

if(get_query_var('page')) { 
    $page = get_query_var('page'); 
} else { 
    $page = 1; 
} 

$row    = 0; 
$files_per_page  = 30; // How many images to display on each page 
$files    = get_field('fisier'); 
$total   = count($files); 
$pages   = ceil($total/$files_per_page); 
$min    = (($page * $files_per_page) - $files_per_page) + 1; 
$max    = ($min + $files_per_page) - 1; 

?> 

<div class="container"> 
    <div class="row"> 
     <div class="col-md-8"> 
      <section id="content"> 
       <div class="wrapper"> 

        <?php while (have_posts()) : the_post(); ?> 
        <?php the_content(); ?> 
        <?php endwhile; ?> 

        <?php if(have_rows('fisier')): ?> 
        <div class="article-files"> 
         <h4>Files</h4> 
         <div class="row"> 
          <?php while (have_rows('fisier')) : the_row(); 
            $row++; 
            if($row < $min) { continue; } 
            if($row > $max) { break; } 
          ?> 
           <div class="col-xs-12 file"> 
           <?php $x = 0; ?> 
           <?php $file = get_sub_field('link'); if($file): ?> 
            <a href="<?php echo $file; ?>" class="file-title" target="_blank"><i class="fa fa-angle-right" aria-hidden="true"></i> <?php the_sub_field('nume_fisier'); ?></a> 
            <div class="file-description"><?php the_sub_field('descriere'); ?></div> 
            <?php $x = 1; ?> 
           <?php endif; ?> 
           <?php $file = get_sub_field('fisier_intern'); if($file): ?> 
            <a href="<?php echo $file; ?>" class="file-title" target="_blank"><i class="fa fa-angle-right" aria-hidden="true"></i> <?php the_sub_field('nume_fisier'); ?></a> 
            <div class="file-description"><?php the_sub_field('descriere'); ?></div> 
            <?php $x = 1; ?> 
           <?php endif; ?> 
           <?php if($x == 0): ?> 
            <a href="#" class="file-title"><i class="fa fa-angle-right" aria-hidden="true"></i> <?php the_sub_field('nume_fisier'); ?></a> 
            <div class="file-description"><?php the_sub_field('descriere'); ?></div> 
            <?php $x = 1; ?> 
           <?php endif; ?> 
           </div> 
          <?php endwhile; ?> 
         </div> 
         <div class="file-pagination"> 
         <?php 
         echo paginate_links(array(
         'base' => get_permalink() . '%#%' . '/', 
         'format' => '?page=%#%', 
         'current' => $page, 
          'show_all' => false, 
          'prev_text' => __('«'), 
          'next_text' => __('»'), 
         'total' => $pages 
        )); 
         ?> 
         </div> <!-- file-pagination --> 
        </div> 
        <?php endif; ?> 

       </div> <!-- wrapper --> 
      </section> <!-- content --> 
     </div> <!-- col --> 
     <div class="col-md-4"> 
      <aside id="sidebar"> 
       <?php get_sidebar(); ?> 
      </aside> <!-- aside --> 
     </div> <!-- col --> 
    </div> <!-- row --> 
</div> <!-- container --> 

<?php get_footer(); ?> 

Код выше не отображает ссылки разбивки на страницы, но если удалить эту часть:

<?php while (have_posts()) : the_post(); ?> 
<?php the_content(); ?> 
<?php endwhile; ?> 

Все работает отлично. Любая идея о том, как я могу это исправить?

Thanks

+0

Извинения, если это не поможет (я на мобильном телефоне, трудно правильно прочитать код), но я не вижу функцию сброса после того, как ваш выход контура. Возможно, поместив это: 'wp_reset_postdata();' между циклом и разбиением на страницы может восстановить исходный запрос для функции –

ответ

0

Решил проблему! Я должен был перенести настройки нумерации страниц после the_content(), как показано ниже:

<?php get_header(); ?> 

<div class="container"> 
    <div class="row"> 
     <div class="col-xs-12"> 
      <h1 class="pagetitle"><?php the_title(); ?></h1> 
     </div> <!-- col --> 
    </div> <!-- row --> 
</div> <!-- container --> 

<div class="container"> 
    <div class="row"> 
     <div class="col-md-8"> 
      <section id="content"> 
       <div class="wrapper"> 

        <?php while (have_posts()) : the_post(); ?> 
        <?php the_content(); ?> 
        <?php endwhile; ?> 


        <?php 

        if(get_query_var('page')) { 
         $page = get_query_var('page'); 
        } else { 
         $page = 1; 
        } 

        $row    = 0; 
        $files_per_page  = 30; // How many images to display on each page 
        $files    = get_field('fisier'); 
        $total   = count($files); 
        $pages   = ceil($total/$files_per_page); 
        $min    = (($page * $files_per_page) - $files_per_page) + 1; 
        $max    = ($min + $files_per_page) - 1; 

        ?> 

        <?php if(have_rows('fisier')): ?> 
        <div class="article-files"> 
         <h4>Files</h4> 
         <div class="row"> 
          <?php while (have_rows('fisier')) : the_row(); 
            $row++; 
            if($row < $min) { continue; } 
            if($row > $max) { break; } 
          ?> 
           <div class="col-xs-12 file"> 
           <?php $x = 0; ?> 
           <?php $file = get_sub_field('link'); if($file): ?> 
            <a href="<?php echo $file; ?>" class="file-title" target="_blank"><i class="fa fa-angle-right" aria-hidden="true"></i> <?php the_sub_field('nume_fisier'); ?></a> 
            <div class="file-description"><?php the_sub_field('descriere'); ?></div> 
            <?php $x = 1; ?> 
           <?php endif; ?> 
           <?php $file = get_sub_field('fisier_intern'); if($file): ?> 
            <a href="<?php echo $file; ?>" class="file-title" target="_blank"><i class="fa fa-angle-right" aria-hidden="true"></i> <?php the_sub_field('nume_fisier'); ?></a> 
            <div class="file-description"><?php the_sub_field('descriere'); ?></div> 
            <?php $x = 1; ?> 
           <?php endif; ?> 
           <?php if($x == 0): ?> 
            <a href="#" class="file-title"><i class="fa fa-angle-right" aria-hidden="true"></i> <?php the_sub_field('nume_fisier'); ?></a> 
            <div class="file-description"><?php the_sub_field('descriere'); ?></div> 
            <?php $x = 1; ?> 
           <?php endif; ?> 
           </div> 
          <?php endwhile; ?> 
         </div> 
         <div class="file-pagination"> 
         <?php 
         echo paginate_links(array(
         'base' => get_permalink() . '%#%' . '/', 
         'format' => '?page=%#%', 
         'current' => $page, 
          'show_all' => false, 
          'prev_text' => __('«'), 
          'next_text' => __('»'), 
         'total' => $pages 
        )); 
         ?> 
         </div> <!-- file-pagination --> 
        </div> 
        <?php endif; ?> 

       </div> <!-- wrapper --> 
      </section> <!-- content --> 
     </div> <!-- col --> 
     <div class="col-md-4"> 
      <aside id="sidebar"> 
       <?php get_sidebar(); ?> 
      </aside> <!-- aside --> 
     </div> <!-- col --> 
    </div> <!-- row --> 
</div> <!-- container --> 

<?php get_footer(); ?> 
Смежные вопросы