Page No.2
<table class="form-table">
<tr valign="top">
<td>Load style sheet</td>
<td><input type="number" name="splcpn_options[style]" value="<?php echo intval( $this->ret_option['style'] ); ?>" min="0" max="6"></td>
<td>* <?php _e( '0:don\'t load style sheet file or the case of specifing style sheet at template, 1:standard square design, 2:circle design, 3:circle white back, 4:circle orange back, 5:simple square, 6:white gradation', $this->domain ); ?></td>
</tr>
<tr valign="top">
<td>Reverse List</td>
<td><select name="splcpn_options[reverse]">
<?php
$selected = array( '', '' );
if ( '1' === $this->ret_option['reverse'] ) {
$selected[1] = ' selected';
} else {
$selected[0] = ' selected';
}
?>
<option value="1"<?php echo $selected[1]; ?>><?php _e( 'reverse list', $this->domain ); ?></option>
<option value="0"<?php echo $selected[0]; ?>><?php _e( 'standard left start', $this->domain ); ?></option>
</select></td>
<td>* <?php _e( 'Reverse the order of list if you select \'reverse list\'', $this->domain ); ?></td>
</tr>
<tr valign="top">
<td>Display of direct Jump box</td>
<td><input type="number" name="splcpn_options[above]" value="<?php echo intval( $this->ret_option['above'] ); ?>" min="2" max="1000"></td>
<td>* <?php _e( 'Input-box of direct jump is showed when page count over this number. Input-box isn\'t displayed when you set number over page count.', $this->domain ); ?></td>
</tr>
<tr valign="top">
<td>Pixel value of madia query's max-width</td>
<td><input type="number" name="splcpn_options[nr_style]" value="<?php echo intval( $this->ret_option['nr_style'] ); ?>" min="0" max="1500"></td>
<td>* <?php _e( 'This number is pixel value of madia query\'s max-width. The style for narrow screen will be showed if this number isn\'t 0. Default is 768.', $this->domain ); ?></td>
</tr>
<tr valign="top">
<td>list of minimum unit</td>
<td><select name="splcpn_options[minimum_unit]">
<?php
$selected = array( '', '' );
if ( '0' === $this->ret_option['minimum_unit'] ) {
$selected[0] = ' selected';
} else {
$selected[1] = ' selected';
}
?>
<option value="1"<?php echo $selected[1]; ?>><?php _e( 'standard', $this->domain ); ?></option>
<option value="0"<?php echo $selected[0]; ?>><?php _e( 'minimun', $this->domain ); ?></option>
</select></td>
<td>* <?php _e( 'Display page-list of minimum requirement unit.', $this->domain ); ?></td>
</tr>
<tr valign="top">
<td>Number of pages that adjacent to current page to display list</td>
<td><input type="number" name="splcpn_options[adjacent_num]" value="<?php echo intval( $this->ret_option['adjacent_num'] ); ?>" min="1" max="5"></td>
<td>* <?php _e( 'Input number of pages that adjacent to current page to list. <br>For example, if you set 2 and when current page is 5, this plug-in will display adjacent pages : 3,4,5,6,7.', $this->domain ); ?></td>
</tr>
<td>Maximum number of larger page to display list</td>
<td><input type="number" name="splcpn_options[larger_page]" value="<?php echo intval( $this->ret_option['larger_page'] ); ?>" min="0" max="5"></td>
<td>* <?php _e( 'Larger page means a multiple of 10. This number is only on the above side of the current page number. <br>For example, if you set 2 and when current page is 1 and page-counts is 50, this plug-in will display larger pages : 1,...,10,20. Enter 0 to disable.', $this->domain ); ?></td>
</tr>
<tr valign="top">
<td>Label of 'to first page'</td>
<td><input type="text" name="splcpn_options[top_label]" value="<?php echo esc_attr( $this->ret_option['top_label'] ); ?>" maxlength="6"></td>
<td>* <?php _e( 'Input text of the link to the top page in less than six characters.', $this->domain ); ?></td>
</tr>
<tr valign="top">
<td>Label of 'to last page'</td>
<td><input type="text" name="splcpn_options[last_label]" value="<?php echo esc_attr( $this->ret_option['last_label'] ); ?>" maxlength="6"></td>
<td>* <?php _e( 'Input text of the link to the last page in less than six characters.', $this->domain ); ?></td>
</tr>
<tr valign="top">
<td>Connection string</td>
<td><input type="text" name="splcpn_options[connection_str]" value="<?php echo esc_attr( $this->ret_option['connection_str'] ); ?>" maxlength="3"></td>
<td>* <?php _e( 'Input text of the connection string to connect away from another links in less than three characters. Empty is disable.', $this->domain ); ?></td>
</tr>
<tr valign="top">
<td>Id string of parent div tag</td>
<td><input type="text" name="splcpn_options[div_id]" value="<?php echo esc_attr( $this->ret_option['div_id'] ); ?>" maxlength="20"></td>
<td>* <?php _e( 'Input text of the id string of parent div tag. Default is "pagenavilist".', $this->domain ); ?></td>
</tr>
<tr valign="top">
<td>Font size</td>
<td><input type="number" name="splcpn_options[font_size]" value="<?php echo intval( $this->ret_option['font_size'] ); ?>" min="-10" max="10"></td>
<td>* <?php _e( 'Set font size. Select 0 to disable. -10 : 0.5em ~ 10 : 1.5em, at intervals of 0.05em.', $this->domain ); ?></td>
</tr>
<tr valign="top">
<td>Text-align of id="toppagelink" <nav> tag</td>
<td><select name="splcpn_options[top_text_align]">
<?php
$selected = array( '', '', '', '' );
if ( '1' === $this->ret_option['top_text_align'] ) {
$selected[1] = ' selected';
} elseif ( '2' === $this->ret_option['top_text_align'] ) {
$selected[2] = ' selected';
} elseif ( '3' === $this->ret_option['top_text_align'] ) {
$selected[3] = ' selected';
} else {
$selected[0] = ' selected';
}
?>
<option value="0"<?php echo $selected[0]; ?>><?php _e( 'disable', $this->domain ); ?></option>
<option value="1"<?php echo $selected[1]; ?>><?php _e( 'left', $this->domain ); ?></option>
<option value="2"<?php echo $selected[2]; ?>><?php _e( 'right', $this->domain ); ?></option>
<option value="3"<?php echo $selected[3]; ?>><?php _e( 'center', $this->domain ); ?></option>
</select></td>
<td>* <?php _e( 'Text-align of id selector "toppagelink" of "nav" tag.', $this->domain ); ?></td>
</tr>
<tr valign="top">
<td>Margin of id="toppagelink" <nav> tag</td>
<td><input type="text" name="splcpn_options[top_margin]" value="<?php echo esc_attr( $this->ret_option['top_margin'] ); ?>" maxlength="21"></td>
<td>* <?php _e( 'Margin of id selector "toppagelink" of "nav" tag. Empty is disable, enter as top:right:bottom:left. This value can have from one to four values same as the format of css.<br>For example, 10, 20:20, 10:0:20 or -20:0:30:50.', $this->domain ); ?></td>
</tr>
<tr valign="top">
<td>Text-align of id="bottompagelink" <nav> tag</td>
<td><select name="splcpn_options[bottom_text_align]">
<?php
$selected = array( '', '', '', '' );
if ( '1' === $this->ret_option['bottom_text_align'] ) {
$selected[1] = ' selected';
} elseif ( '2' === $this->ret_option['bottom_text_align'] ) {
$selected[2] = ' selected';
} elseif ( '3' === $this->ret_option['bottom_text_align'] ) {
$selected[3] = ' selected';
} else {
$selected[0] = ' selected';
}
?>
<option value="0"<?php echo $selected[0]; ?>><?php _e( 'disable', $this->domain ); ?></option>
<option value="1"<?php echo $selected[1]; ?>><?php _e( 'left', $this->domain ); ?></option>
<option value="2"<?php echo $selected[2]; ?>><?php _e( 'right', $this->domain ); ?></option>
<option value="3"<?php echo $selected[3]; ?>><?php _e( 'center', $this->domain ); ?></option>
</select></td>
<td>* <?php _e( 'Text-align of id selector "bottompagelink" of "nav" tag.', $this->domain ); ?></td>
</tr>
<tr valign="top">
<td>Margin of id="bottompagelink" <nav> tag</td>
<td><input type="text" name="splcpn_options[bottom_margin]" value="<?php echo esc_attr( $this->ret_option['bottom_margin'] ); ?>" maxlength="21"></td>
<td>* <?php _e( 'Margin of id selector "bottompagelink" of "nav" tag. Same as "top_margin".', $this->domain ); ?></td>
</tr>
</table>
<p>* <?php _e( 'However, about the style, I recommend that you set to disable the above options about style and described in the style sheet.', $this->domain ); ?></p>
<?php submit_button(); ?>
</form>
<p><?php _e( 'The setted optional value is deleted from the data-base when you uninstall this plug-in on the plug-in page', $this->domain ); ?></p>
<hr>
explain.php にはこの後に使用説明書きの部分がつづくのですが、その部分はここではあまり意味のないことなので省略。
そしていよいよ本命のページリスト表示関数。これも長いので部分的にとり出していきます。
この部分において、配列による引数があればその値でオプション値の上書きということをやっています。(36行~41行)ここでちょっと注意が必要なのは配列ではなく設定されている引数$dirの存在。この引数の存在によって、func_num_args()は配列による引数が無い状態でも1を返します。当然、$args = func_get_args()の戻り値である配列の$args[0]には$dir の値が入っている事となり、配列で渡された引数の値は$args[1]に配列で収まっているという事になります。
そして、31行目のget_query_var('paged') で現在のページ番号を所得しているのですが、この”paged”はクエリ変数(Query Vars)です。ここで得られるページ番号は1ページの場合は0が返って来ます。で、実は$paged という変数にも値が入っていて、おもしろいことにこちらは1ページの場合ちゃんと1が入っているのですね。と、いうことでこの$paged をそのまま使用すれば良いのかもしれませんが、なんとなく使って良い物かどうかと・・・?
<?php
// ↓class 続き
// direct jump用のinputを表示するための処理
// パーマリンク設定が基本のときのためにurlパラメータを取得
private function get_url_parameter() {
$params = $_GET;
if ( $params ) {
foreach ( $params as $key => $val ) {
if ( 'paged' !== $key ) {
$tmpkey = esc_attr( $key );
$tmpval = esc_attr( $val );
$this->url_parameter[ $tmpkey ] = $tmpval;
}
}
}
}
// 以降、ページナビを表示する関数
// 引数の$dirはサイトの上部と下部に表示する場合にidを別にするためのもの
// その他の引数はオプション値と同じで配列により渡す
public function splcpn_echopagelist( $dir = 0 ) {
global $wp_query;
// 現在のページの基本となるurl が取得出来てない場合は、取得する関数を呼び出す。
if ( '' === $this->current_url ) {
$this->treat_current_url();
}
// ページ番号と合計ページ数を取得
$page_no = ( get_query_var('paged') ) ? intval( get_query_var('paged') ) : 1;
$page_counts = intval( $wp_query->max_num_pages );
// 配列による引数があればオプション値を上書き
// 規定の引数$dirがあるためfunc_num_args()>1であり$args[1]が配列により渡された引数となる
if ( func_num_args() > 1 ) {
$args = func_get_args();
$current_option = array_merge( $this->ret_option, $args[1] );
} else {
$current_option = $this->ret_option;
}
// 引数でmax_page_numが指定されている場合はその数値を使用する
if ( isset( $current_option['max_page_num'] ) ) {
$page_counts = $current_option['max_page_num'];
}
$splcpn_above = intval( $current_option['above'] );
// ↓function splcpn_echopagelist 続く
// ↓class 続く
?>
6行目からのget_url_parameter() で現在表示されているページのurlにあるパラメータを取得しています。
ここもv2.0で変更した部分で、メインのsplcpn_echopagelist()関数の外へだして、プラグイン読み込み時に一度だけ実行されるようにしました。
これはタグやカテゴリー、日付けテンプレートで表示されている時に、Direct input & Jump のform 用に必要なのです。といっても、それが必要なのはパーマリンク設定が基本の時だけのことではあります。
WordPressはhttpリクエストに含まれるクエリ文字列をパブリッククエリ変数として解釈し、パーマリンクが設定されている場合は、それによるリライトルールによってWordPressクエリを実行することになります。
ここでちょっと引用してみると、
「このWordPressがhttpリクエストからパブリッククエリ変数を生成する処理は、POSTのクエリ文字列、GETのクエリ文字列、リライトルール適用後の表現の順になります。同じパブリッククエリ変数が複数の方法で指定された場合は、最初に見つかったものが優先されます。」 引用文献:詳解 WordPress プライム・ストラテジー株式会社著 O'REILLY → 3章 WordPress の実行プロセス 98P
なるほど、と、いうことなので、パーマリンクが基本以外に設定されている場合は現在のurlにページ番号だけをGETで送信すれば、そのページ番号が表示されるということだと思います。実際にローカルな環境でテストしてみた限りにおいては望むべく結果を得ることが出来ました。
しかし、パーマリンク設定が基本の時には、現在のurlに元々付加されているクエリ文字列を、form送信の時に一緒に送信する必要があるということだと思うので、paged以外のクエリ文字列をinput hidden要素で送信すべく、取得しているということなのです。
ちなみに、実際のページリストを生成する部分で使用している、 get_pagenum_link() に関しては、パーマリンク設定が基本だろうがカスタムであろうが、付加されているパラメータを含めて全てやってくれるので、余計な事を考える必要はありません。ただ、ページ番号をひたすらに渡すだけで良いと。
しかし、初めてページネーションを自作した時はそうじゃなかったように思うのですが・・・、勝手につけたパラメータは自分でつけないといけなかったように記憶していますし、まえのコードを見るとそうなっていますし・・・。単なる思い違いをしていただけだったのか、はたまた改良されたのか?まぁ、使いやすくなったのでありがたいことには違いないですね。
《 get_pagenum_link() に関して 》
と、いうことでちょっとまた寄り道をしてget_pagenum_link() のことなどを。
このget_pagenum_link() はwp-includes/link-template.php の2060行目あたりに書かれています。
これによって生成されるリンクの元になっているのは、wp-includes/functions.php のremove_query_arg() というかその関数が呼び出しているadd_query_arg() において取得されている、 $_SERVER['REQUEST_URI'] と、なります。
元になっているのが$_SERVER['REQUEST_URI'] なので種々のパラメータも含まれているし、元々のurl に対してpaged のパラメータを付け直しているので、余計なことを考えなくてもいいわけです。
改めてしっかり見てみると、まずは$_SERVER['REQUEST_URI'] で取得したurl からremove_query_arg() で”paged=” のパラメータを取り除いたものが基本になってます。しかし、これだと基本設定以外のカスタムなパーマリンク設定における”/page/3” などのページ指定を取り除くことは出来ないので、preg_replaceを使用して正規表現にて消去しています。
そして、プロトコルやホストの部分を整形して、パーマリンクが基本設定の場合はadd_query_arg() にて、
<?php
if ( ! $wp_rewrite->using_permalinks() || is_admin() ) {
$base = trailingslashit( get_bloginfo( 'url' ) );
if ( $pagenum > 1 ) {
$result = add_query_arg( 'paged', $pagenum, $base . $request );
} else {
$result = $base . $request;
}
}
?>
と、言う具合で”paged=” のパラメータを付加しています。
ちなみに、$wp_rewrite->using_permalinks() は、パーマリンク設定が基本であるか、カスタムであるかの判別ができます。基本設定の場合はfalse を返します。また、trailingslashit()関数 においては、引数で渡された文字列の最後に'/'がついていてもいなくても、最終的に'/'が一つ付加された状態の文字列を返します。
一方の、カスタムなパーマリンク設定の場合においては、
<?php
if ( $pagenum > 1 ) {
$request = ( ( !empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( $wp_rewrite->pagination_base . "/" . $pagenum, 'paged' );
}
?>
と、言う具合に”/page/3” などのページ指定の部分を付加しています。
こちらの場合の、user_trailingslashit()関数 に関しては、カスタムなパーマリンク設定の場合はurl の最後に'/'が付く場合と無い場合があり、その有無を設定から判別して付けるなり無くすなりをしてくれます。$wp_rewrite->pagination_base の値の文字列のデフォルトは”page” であると思われます。
実際のコードを見てみると、パラメータ設定が基本の場合で二度、それ以外のカスタムなパーマリンク設定においてはそれに加えて二、三度、preg_replace による正規表現での置換が行われます。
そのあたりを考えてみると、プラグイン読み込みの時に一度だけページ番号に1を指定してget_pagenum_link() にて現在表示されているページの素のurl を取得しておいて、それを元にしてパーマリンク設定が基本かカスタムかを判別してそれぞれ”paged=” か”/page/” を付加するだけにすれば、速度的に有効なのではと思い、そのように変更してあります。
《 get_pagenum_link() に関して 》はここまで。
続いての部分は、オプション設定値による無害化やら種々の処理。
<?php
// ↓class 続き
// ↓function splcpn_echopagelist 続き
// 最外の<nav>タグのid属性の設定
$topnav = 'bottom';
if ( 1 === $dir ) {
$topnav = 'top';
}
// 逆順表示のための設定
$rev = intval( $current_option['reverse'] );
// ラベル文字列の設定
$totop = esc_html( $current_option['top_label'] );
$tolast = esc_html( $current_option['last_label'] );
if ( 0 === $rev ) {
$totop = '«' . $totop;
$tolast .= '»';
$pr = '<';
$nt = '>';
} else {
$totop .= '»';
$tolast = '«' . $tolast;
$pr = '>';
$nt = '<';
}
// 現在のページに隣接するページ番号をいくつ表示するかの設定
$adjacent = intval( $current_option['adjacent_num'] );
if ( $adjacent > 5 or $adjacent < 1 ) {
$adjacent = 3;
} else {
++$adjacent;
}
// 10の倍数のページ番号をいくつ表示するかの設定
$largerp = 0;
$largerpnum = intval( $current_option['larger_page'] );
if ( $largerpnum > 5 or $largerpnum < 0) {
$largerp = 30 + 10;
$largerpnum = 3;
} else {
$largerp = $largerpnum * 10 + 10;
}
// 間隔が100より多い時に、100の位のページを表示する。
$distant = intval ( $current_option['distant_num'] );
if ( $distant > 5 or $distant < 0 ) {
$distant = 4;
} else {
++$distant;
}
// ページ番号の間隔をつなく文字列の設定
$connectstr = '';
if ( 0 !== $largerp ) {
if ( $current_option['connection_str'] ) {// 0, '0', '', null, array()は全てfalse
$connectstr = esc_html( substr( $current_option['connection_str'], 0, 3 ) );
$connectstr = '<span class="extend nrnodisp">' . $connectstr . '</span>';
}
}
$idstr = '';
$idstr = $current_option['div_id'];
if ( 'pagenavilist' !== $idstr ) {
if ( ! $idstr ) {
$idstr = 'pagenavilist';
} else {
$pattern = '/[^a-zA-Z-_]+/';
if ( preg_match( $pattern, $idstr ) ) {
$idstr = 'pagenavilist';
}
}
}
// 表示した10の倍数ページの最大値をいれる変数
$tenth = 0;
// 表示した10の倍数ページの個数
$tenthnum = 0;
// 表示した現在のページに隣接するページ番号の最大値をいれる変数
$maxnum = 0;
$titles = array( '', '', '', '' );
//$showtitleに1を指定した場合、両端のリンクタイトルが表示
$showtitle = 0;
if ( 1 === $showtitle ) {
$titles[0] = ' title="Jump! newest posts page"';
$titles[1] = ' title="Next newer posts page!"';
$titles[2] = ' title="Previous older posts page!"';
$titles[3] = ' title="Jump! oldest posts page"';
}
// フォントサイズ、テキストアライン、マージンを表示するための設定
$fontsize = intval( $current_option['font_size'] );
if ( 1 === $dir ) {
$textalign = intval( $current_option['top_text_align'] );
$margin = $current_option['top_margin'];
} else {
$textalign = intval( $current_option['bottom_text_align'] );
$margin = $current_option['bottom_margin'];
}
if ( '' !== $margin and ! is_null( $margin ) ) {// 0または’0’は有効な数字
$pattern = '/[^0-9pxPX:\-]+/';
if ( preg_match( $pattern, $margin ) ) {
$margin = '';// 余計な文字列が含まれていた場合は処理しない
} else {
if ( false !== strpos( $margin, ':' ) ) {// strposは if ( strpos(...) )ではダメ!先頭にある場合は0が戻り値
$tmpmargin = explode( ':', $margin );
$margins = '';
$margincount = 0;
foreach ( $tmpmargin as $val ) {
if ( '' !== $val and ! is_null( $val ) ) {
$value = intval( $val );
if ( 0 === $value ) {
$margins .= '0 ';
} else {
$margins .= strval( $value ) . 'px ';
}
++$margincount;
}
if ( 4 === $margincount ) {
break;
}
}
$margins = trim( $margins );
} else {
$margin = intval( $margin );
if ( 0 === $margin ) {
$margins = '0';
} else {
$margins = strval( $margin ) . 'px';
}
}
}
} else {
$margin = '';
}
if ( $textalign <0 or $textalign >3 ) {
$textalign = 0;
}
// 吐き出すスタイル設定の文字列を組み立て
$navstyle = '';
if ( 0 !== $fontsize or 0 !== $textalign or '' !== $margin ) {
$navstyle = ' style="';
if ( 0 !== $fontsize ) {
$emsize = 1 + 0.05*$fontsize;
$navstyle .= 'font-size:' . strval( $emsize ) . 'em;';
}
if ( 0 !== $textalign ) {
$alignstr = 'center';
if ( 1 === $textalign ) {
$alignstr = 'left';
} elseif ( 2 === $textalign ) {
$alignstr = 'right';
}
$navstyle .= 'text-align:' . $alignstr . ';';
}
if ( '' !== $margin ) {
$navstyle .= 'margin:' . $margins . ';';
}
$navstyle .= '"';
}
// ↓function splcpn_echopagelist 続く
// ↓class 続く
?>
そして実際にページリストを生成する部分になります。
v3.0 においてはこの下の部分のほとんどを刷新しています。
<?php
// ↓class 続き
// ↓function splcpn_echopagelist 続き
// ここから実際のリスト表示
//通常表示用の配列
$liststr = array();
$templink = '';
if ( $page_counts > 1 ) {
echo '<nav id="' . $topnav . 'pagelink"' . $navstyle .'><div class="' . $idstr . '">';
echo '<!-- Simplistic Page-navi list ver.3.0 -->';
echo '<form method="get" class="jump-form" action="">';
echo '<span class="pages">' . $page_no . '/' . $page_counts . '</span>';
// すでにリストが作成されてストアされていればそれを表示
if ( $this->page_list ) {
$liststr = $this->page_list;
if ( 1 === $rev ) {
// 逆順の時
$liststr = array_reverse( $this->page_list );
}
if ( '0' === $current_option['minimum_unit'] ) {
// 最小限の要素の表示の時は二次元め$liststr[][1]に1を指定してあるものだけを表示
foreach ( $liststr as $val ) {
if ( 1 === $val[1] ) {
echo $val[0];
}
}
} else {
foreach ( $liststr as $val ) {
echo $val[0];
}
}
// 二度目に使用したあとはメモリーを消去
$this->page_list = array();
} else {
//ここから 一度目の呼び出しの時のリスト作成
$templink = '<a href="' . $this->make_pagenumlink() . '" class="first"' . $titles[0] . '>' . $totop . '</a>';
if ( '0' === $current_option['minimum_unit'] ) {
if ( 1 !== $page_no ) {
// 最小限の要素の表示用に、二次元め$liststr[][1]に1を指定
$liststr[] = array( $templink, 1 );
}
} else {
if ( ( $page_no - $adjacent ) > 0 ) {
$liststr[] = array( $templink, 0 ) ;
}
}
if ( $page_no > 1 ) {
$templink = '<a href="' . $this->make_pagenumlink( $page_no - 1 ) . '" class="previouspostslink" rel="next"' . $titles[1] . '>' . $pr . '</a>';
$liststr[] = array( $templink, 1 );
}
$list_ary = array();
$connectflga = 0;
$connectflgb = 0;
$bigten = $page_counts;
$tennum = $page_counts;
// カレントページの登録、keyもカレントページ番号
$list_ary[ $page_no ] = '<span class="current">' . $page_no . '</span>';
// カレントページに隣接のページ
$i = 1;
while ( $i < $adjacent ) {
// カレントページよりも大きい番号側
$tmp = $page_no + $i;
if ( $tmp <= $page_counts ) {
$list_ary[ $tmp ] = '<a href="' . $this->make_pagenumlink( $tmp ) . '" class="pagelarger nrnodisp">' . $tmp . '</a>';
$bigten = $tmp;
}
// カレントページよりも小さい番号側
$tmp = $page_no - $i;
if ( $tmp >= 1 ) {
$list_ary[ $tmp ] = '<a href="' . $this->make_pagenumlink( $tmp ) . '" class="pagelarger nrnodisp">' . $tmp . '</a>';
$tennum = $tmp;
}
$i++;
}
// カレントページに近い10の単位のページで大きい番号側
if ( 0 < $largerpnum ) {
$lcount = 1;
for ( $i = 1; $i < 10; $i++ ) {
$tennum = floor ( ( $page_no + 10 * $i ) / 10 ) * 10;
// 直近の10の単位のページがカレントページ隣接のページとだぶらないためと全ページ数を超えないため
if ( $tennum > $page_no + $adjacent and $tennum < $page_counts ) {
if ( ! $connectflga ) {
$list_ary[ $tennum - 1 ] = $connectstr;
$connectflga = 1;
}
$list_ary[ $tennum ] = '<a href="' . $this->make_pagenumlink( $tennum ) . '" class="pagelarger nrnodisp">' . $tennum . '</a>';
$lcount++;
// この下の3の数値が表示されるページラベルの数。ループの10回は無限ループ阻止のためで意味は無い
if ( $lcount > $largerpnum ) {
$list_ary[ $tennum + 1 ] = $connectstr;
$bigten = $tennum;
break;
}
}
}
$lcount = 1;
for ( $i = 1; $i < 10; $i++ ) {
$tennum = ceil ( ( $page_no - 10 * $i ) / 10 ) * 10;
// 直近の10の単位のページがカレントページ隣接のページとだぶらないためと1ページより少なくならないため
if ( $tennum < $page_no - $adjacent and $tennum > 1 ) {
if ( ! $connectflgb ) {
$list_ary[ $tennum + 1 ] = $connectstr;
$connectflgb = 1;
}
$list_ary[ $tennum ] = '<a href="' . $this->make_pagenumlink( $tennum ) . '" class="pagelarger nrnodisp">' . $tennum . '</a>';
$lcount++;
// この下の3の数値が表示されるページラベルの数。ループの10回は無限ループ阻止のためで意味は無い
if ( $lcount > $largerpnum ) {
$list_ary[ $tennum - 1 ] = $connectstr;
break;
}
}
}
}
// 両端のラベルとの間隔が広い場合にその間に100の位のページを表示
if ( $distant ) {
if ( $page_no < 20 and $page_counts - $bigten > 100 ) {
// 最大の10の単位のページから、その数を繰り上げて直近の100の位の数字を得る。
$bigten = ceil ( $bigten / 100 ) * 100;
if ( 0 === $connectflga ) {
$list_ary[ $bigten - 1 ] = $connectstr;
}
// ループの回数を増やせば可能なだけ100の単位のページラベルが増える
for ( $i = 1; $i < 4; $i++ ) {
if ( $bigten < $page_counts ) {
$list_ary[ $bigten ] = '<a href="' . $this->make_pagenumlink( $bigten ) . '" class="pagelarger nrnodisp">' . $bigten . '</a>';
} else {
break;
}
$bigten += 100;
}
if ( $i > 1 ) {
$list_ary[ $bigten + 1 ] = $connectstr;
}
}
if ( $page_counts - $page_no < 20 and $tennum > 100 ) {
// 最小の10の単位のページから、その数を繰り下げて直近の100の位の数字を得る。
$tennum = floor ( $tennum / 100 ) * 100;
if ( 0 === $connectflgb ) {
$list_ary[ $tennum + 1 ] = $connectstr;
}
for ( $i = 1; $i < 4; $i++ ) {
if ( $tennum > 1 ) {
$list_ary[ $tennum ] = '<a href="' . $this->make_pagenumlink( $tennum ) . '" class="pagelarger nrnodisp">' . $tennum . '</a>';
} else {
break;
}
$tennum -= 100;
}
if ( $i > 1 ) {
$list_ary[ $tennum - 1 ] = $connectstr;
}
}
}
// リストをkeyでソート
ksort( $list_ary );
foreach ( $list_ary as $key => $val ) {
$mnflg = $page_no === $key ? 1 : 0;
$liststr[] = array( $val, $mnflg );
}
if ( $page_no < $page_counts ) {
$templink = '<a href="' . $this->make_pagenumlink( $page_no + 1 ) . '" class="nextpostslink" rel="prev"' . $titles[2] . '>' . $nt . '</a>';
$liststr[] = array( $templink, 1 );
}
$templink = '<a href="' . $this->make_pagenumlink( $page_counts ) . '" class="last"' . $titles[3] . '>' . $tolast . '</a>';
if ( '0' === $current_option['minimum_unit'] ) {
if ( $page_no != $page_counts ) {
$liststr[] = array( $templink, 1 );
}
} else {
if ( $page_counts > ( $page_no + $adjacent - 1 ) ) {
$liststr[] = array( $templink, 0 );
}
}
$this->page_list = $liststr;
if ( 1 === $rev ) {
$liststr = array_reverse( $liststr );
}
if ( '0' === $current_option['minimum_unit'] ) {
foreach ( $liststr as $val ) {
if ( 1 === $val[1] ) {
echo $val[0];
}
}
} else {
foreach ( $liststr as $val ) {
echo $val[0];
}
}
}
// direct jump 用のinput box 表示用の処理
if ( $page_counts > $splcpn_above ) {
if ( $this->url_parameter ) {
foreach ( $this->url_parameter as $key => $val ) {
echo '<input type="hidden" name="' . $key . '" value="' . $val . '">';
}
}
echo '<span class="jumpnav"><input type="number" class="direct-jump" value="' . $page_no . '" name="paged" min="1" max="' . $page_counts . '" title="Direct Jump : input page number and push enter key."></span>';
}
echo '</form>';
echo '</div></nav>';
}
}
// ↑function splcpn_echopagelist ここまで
// ↓class 続く
?>
class最後の部分は、翻訳ファイルの読み込み処理とナロースクリーン用のスタイルをwp_head()に吐き出すための処理。
<?php
// ↓class 続き
// 翻訳ファイル読み込み関数
private function load_text_domain() {
if ( $this->td_loaded ) {
return;
}
$locale = get_locale();
$mofile = dirname( __FILE__ );
$mofile .= "/{$this->domain}-{$locale}.mo";
load_textdomain( $this->domain, $mofile );
$this->td_loaded = true;
}
// ナロースクリーン用に必要最小限の構成にするためのスタイルを吐き出す処理
public function echo_nr_style() {
$tarwidth = intval( $this->ret_option['nr_style'] );
?>
<style type="text/css">
@media screen and (max-width:<?php echo strval( $tarwidth ); ?>px){
.nrnodisp{
display:none;
}
}
</style>
<?php
}
}
// ↑class Simplistic_Page_Navi_List 終了
?>
これにてclassは終了!
Post : 2015/09/02 18:11