私は2のWP_Query
のループを静的なホームページに貼り付けました。ページネーションは両方のループで機能しますが、最初のループの2ページ目に行くと、2番目のループも2ページ目に移動します。両方のループのページ分割を分けることはできますか?WordPress:静的なページの複数のループのページ番号
私は静的なフロントページにあるので、の代わりにpage
パラメータを使用しました。
2番目の問題は、ページング時にアンカーポイントとして機能するために両方のセクションにIDを追加したことですが、これも機能していないようです。
最初のクエリ:
<section class="section" id="event">
<div class="container">
<div class="row">
<div class="col-xs-12 text-center">
<h2>Events</h2>
<p class="lead">Some of our future events</p>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<?php
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$args = array (
'post_type' => 'events',
'posts_per_page' => 3,
'meta_key' => 'datum',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'paged' => $paged,
);
$the_query = new WP_Query($args); ?>
<?php if ($the_query->have_posts()) : ?>
<!-- pagination here -->
<!-- the loop -->
<?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
<div class="event">
<div class="row">
<div class="col-sm-6 col-md-4">
<?php if (has_post_thumbnail()): ?>
<?php the_post_thumbnail('event-img'); ?>
<?php endif; ?>
</div>
<div class="col-sm-6 col-md-8 event-body">
<h4><?php the_title(); ?></h4>
<p class="lead"><?php the_field('datum') ?> @<?php the_field('locatie') ?></p>
<p><?php the_content(); ?></p>
</div>
</div>
</div>
<?php endwhile; ?>
<!-- end of the loop -->
</div>
<div class="col-xs-12">
<nav class="text-center">
<ul class="pagination">
<li>
<?php
$big = 999999999; // need an unlikely integer
echo paginate_links(array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '?paged=%#%#event',
'current' => max(1, get_query_var('page')),
'total' => $the_query->max_num_pages,
'prev_text' => __('« '),
'next_text' => __(' »'),
));
?>
</li>
</ul>
</nav>
</div>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php _e('Sorry, Geen evenementen gevonden!.'); ?></p>
<?php endif; ?>
</div>
</div>
</section>
2番目のクエリ
<section class="section" id="gallery">
<div class="container">
<div class="row">
<div class="col-xs-12 text-center">
<h2>Gallery</h2>
<p class="lead">Some of our past events</p>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<?php
$paged_gallery = (get_query_var('page')) ? get_query_var('page') : 1;
$gallery_args = array (
'post_type' => 'gallerij',
'posts_per_page' => 6,
'paged' => $paged_gallery,
);
$the_query_gallery = new WP_Query($gallery_args); ?>
<?php if ($the_query_gallery->have_posts()) : ?>
<div class="row">
<!-- pagination here -->
<!-- the loop -->
<?php while ($the_query_gallery->have_posts()) : $the_query_gallery->the_post(); ?>
<div class="col-sm-6 col-md-4 album">
<div class="cover-text">
<a href="<?php (has_post_thumbnail()) ? the_post_thumbnail_url() : "" ?>" data-lightbox="<?php the_ID(); ?>">
<?php if (has_post_thumbnail()): ?>
<?php the_post_thumbnail('gallery-img', array('class' => 'img-rounded')); ?>
<?php endif; ?>
</a>
<h3 class="album-title"><?php the_title(); ?></h3>
</div>
<div class="gallery-container">
<?php
$images = get_field('album');
if($images): ?>
<?php foreach($images as $image): ?>
<a href="<?php echo $image['url']; ?>" data-lightbox="<?php the_ID(); ?>"></a>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>
<?php endwhile; ?>
</div>
</div>
<div class="col-xs-12">
<nav class="text-center">
<ul class="pagination">
<li>
<?php
$big = 999999999; // need an unlikely integer
echo paginate_links(array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '?paged=%#%#gallery',
'current' => max(1, get_query_var('page')),
'total' => $the_query_gallery->max_num_pages,
'prev_text' => __('« '),
'next_text' => __(' »'),
));
?>
</li>
</ul>
</nav>
</div>
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php _e('Sorry, Geen albums gevonden!.'); ?></p>
<?php endif; ?>
</div>
</div>
</section>
更新 が見つかり、このトピック:https://wordpress.stackexchange.com/questions/47259/multiple-wp-query-loops-with-pagination
まさに私の問題であり、BU私は解決策を適用し、今はpaginate_links()が私のフォーマットを無視しているようです。私は静的なフロントページを使用しているので、 'ページ'の代わりに 'ページ'にソリューションを更新しました。
私はこの行を変更する必要があることを意味しますか? '$ paged_gallery =(get_query_var( 'page'))? get_query_var( 'page'):1; 'をカスタムソリューションに追加するか、' paginate_links() '機能全体を書き直す必要がありますか? – Christophvh
$ paged_gallery = isset($ _ GET ['gallery_page'])に変更しますか? $ _GET ['gallery_page']:1; そして、URLを使用して値を変更します。 something.com?gallery_page=2 – damlys