メニュー 閉じる

WPでページネーションにアンカーリンク

■元コード

<div class="pagenation">
<?php
//ページネーション
if ( $the_query->max_num_pages > 1 ) {
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => 'page/%#%/',
'current' => max( 1, $paged ),
'total' => $the_query->max_num_pages,
'type' => 'list',
'prev_text' => '« 前へ',
'next_text' => '次へ »'
) );
}
wp_reset_postdata();
?>
</div>

■アンカーリンク追加コード

<div class="pagenation">
<?php
//ページネーション
if ( $the_query->max_num_pages > 1 ) {
echo paginate_links( array(
'base' => str_replace( $big, '%#%#pagination-container', esc_url( get_pagenum_link( $big ) ) ),
'format' => 'page/%#%/',
'current' => max( 1, $paged ),
'total' => $the_query->max_num_pages,
'type' => 'list',
'prev_text' => '« 前へ',
'next_text' => '次へ »'
) );
}
wp_reset_postdata();
?>
</div>

‘base’ => str_replace( $big, ‘%#%’, esc_url( get_pagenum_link( $big ) ) ), に
アンカーリンク名の「#pagination-container」を追加して
‘base’ => str_replace( $big, ‘%#%#pagination-container’, esc_url( get_pagenum_link( $big ) ) ), とする。

あとはHTMLにアンカー先「id=”pagination-container”」を記述すればOK

末尾に「/」が入ってしまう場合はダッシュボードから
パーマリンクのカスタム構造で「/」を消せばよい。