1
我在Wordpress中有這個自定義模板,其中包含一個分頁ACF字段的腳本。這裏是源代碼:當the_content存在時,ACF分頁不工作
<?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; ?>
一切完美的作品。任何關於如何解決這個問題的想法?
謝謝
道歉,如果這是沒有幫助(我是移動的,很難正確讀取的代碼),但我沒有看到一個復位功能後,您的循環輸出。也許在循環和分頁之間放置:'wp_reset_postdata();'可能會恢復原來的函數查詢 –