Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

WordPress Snippet

ワードプレスをカスタマイズしよう

WordPressの固定ページで、ページネーションを行う場合、query_post() は、使わない方がいいとか、諸説入り乱れて、かつ、コーディングも、そこそこ面倒だったりします。

このようなワードプレス界隈の喧騒、の外側には、javascriptによるページネーションが可能だよ、とか WordPressのコードをもっと簡単にする事ができそうなヒントも意外とあったりします。

このページでは、jQueryでのページネーションを試しています。

ページネーション部分は、jQueryにお任せになるので、テンプレート上で記述するコードは、

<?php
	$paging_contents= get_posts( 'numberposts=-1' );
 
if ( $paging_contents ) {

	$html_structure = '<li><a href="%1$s">%2$s</a></li>';
	$html_list_wrapper= '<ul id="content">%1$s</ul>';
	$html_pagenate_links_wrapper= '<p class="pagenate_links">%1$s</p>';
	$content 					= '';
	
 foreach ($paging_contents as $q){
 
 $content .= sprintf( $html_structure, esc_url( get_permalink( $q->ID ) ), esc_html( $q->post_title ) );
 }
 
 printf( $html_list_wrapper, $content );
}
?>

たったこれだけで、完了。

後は、ヘッダーに

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.pages.js"></script>
<script type="text/javascript">
$(document).ready(function() {
	$("div.holder").jPages({
	 containerID : "content",
	 perPage: 5
 	});
});
</script>

たったこれだけのコードを、出力するだけで、あの面倒なページネーションが出来てしまいます。

これだけの簡単さなので、投稿にリストについて、ページングを追加するのも、難しい作業ではなくなるのではないかと思います。

Simple client side pagination using jquery

関連

CSS pagination – WordPress Snippet