[英]WordPress - Add Numeric Pagination.
I am using the Numeric Post Navigation code in my wordpress theme. 我在wordpress主题中使用数字后导航代码。 I have set Blog page show at most as 3 for 24 posts. 我将博客页面显示最多设置为24个帖子中的3个。 So that the page navigation displays 8 pages. 这样页面导航显示8页。 eg: 1 2 3 ... 8
. 例如: 1 2 3 ... 8
。 But actually the page navigation shows me 1 2 3 ? 8
但实际上页面导航显示我1 2 3 ? 8
1 2 3 ? 8
. 1 2 3 ? 8
。 Now my question what is the error in the below code. 现在我的问题是下面代码中的错误是什么。 Why its showing ?
为何展示?
instead of dot. 而不是点。 Please any one help me. 请任何人帮助我。
My code is, 我的代码是,
function wpbeginner_numeric_posts_nav() {
if( is_singular() )
return;
global $wp_query;
/** Stop execution if there's only 1 page */
if( $wp_query->max_num_pages <= 1 )
return;
$paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
$max = intval( $wp_query->max_num_pages );
/** Add current page to the array */
if ( $paged >= 1 )
$links[] = $paged;
/** Add the pages around the current page to the array */
if ( $paged >= 3 ) {
$links[] = $paged - 1;
$links[] = $paged - 2;
}
if ( ( $paged + 2 ) <= $max ) {
$links[] = $paged + 2;
$links[] = $paged + 1;
}
echo '<div class="navigation"><ul>' . "\n";
/** Previous Post Link */
if ( get_previous_posts_link() )
printf( '<li>%s</li>' . "\n", get_previous_posts_link() );
/** Link to first page, plus ellipses if necessary */
if ( ! in_array( 1, $links ) ) {
$class = 1 == $paged ? ' class="active"' : '';
printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' );
if ( ! in_array( 2, $links ) )
echo '<li>…</li>';
}
/** Link to current page, plus 2 pages in either direction if necessary */
sort( $links );
foreach ( (array) $links as $link ) {
$class = $paged == $link ? ' class="active"' : '';
printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link );
}
/** Link to last page, plus ellipses if necessary */
if ( ! in_array( $max, $links ) ) {
if ( ! in_array( $max - 1, $links ) )
echo '<li>…</li>' . "\n";
$class = $paged == $max ? ' class="active"' : '';
printf( '<li%s><a href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );
}
/** Next Post Link */
if ( get_next_posts_link() )
printf( '<li>%s</li>' . "\n", get_next_posts_link() );
echo '</ul></div>' . "\n";
}
Page Navigation in front end 前端页面导航
<?php wpbeginner_numeric_posts_nav(); ?>
I think you might have some encoding problems, because I see that instead of using the 3 dots ...
you are using the special character called "horizontal ellipsis" -> …
which combines 3 dots in a single character (try to select both dots provided and you will see the difference, the first example are 3 chars, and the second, 1 single char). 我想你可能会遇到一些编码问题,因为我看到的不是使用3个点...
而是使用了名为“水平省略号”的特殊字符 - > …
它在一个字符中组合了3个点(尝试选择两个点提供,你会看到差异,第一个例子是3个字符,第二个例子是1个字符。)
When the encoding is wrong and the browser cannot find a specif character in its characters table, it will just display it as a question mark by default. 当编码错误且浏览器在其字符表中找不到特定字符时,默认情况下它只会显示为问号。
There are several possible solutions: 有几种可能的解决方案:
Replace the character for simple dots in your code where this comment is: 替换此注释所在代码中的简单点的字符:
/** Link to last page, plus ellipses if necessary */
Between the <li>
's 在<li>
之间
Try to set your page to UTF-8, putting this: 尝试将您的页面设置为UTF-8,将此设置为:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
In your <head>
. 在你的<head>
。
Use the html special char code to display that character instead of displaying it directly, which is called horizontal ellipsis and should be represented like this: …
使用html特殊字符代码来显示该字符而不是直接显示它,这称为水平省略号,应该表示如下: …
You can use the first solution, or any/both of the last 2 solutions I provided to fix your problem 您可以使用第一个解决方案,或我提供的最后两个解决方案中的任何一个/两个来解决您的问题
Note : 注意 :
I just remembered that the encoding problem could come from php itself, so you could try adding this to your script just in case: 我只记得编码问题可能来自php本身,所以你可以尝试将它添加到你的脚本以防万一:
mb_internal_encoding("UTF-8");
Source : http://www.php.net/manual/en/function.mb-internal-encoding.php 资料来源: http : //www.php.net/manual/en/function.mb-internal-encoding.php
The question mark may be a font-related issue. 问号可能是与字体相关的问题。 Some fonts, if they do not contain the written character on your page, display a question mark. 某些字体(如果它们不包含页面上的书写字符)会显示问号。
Make sure you typed the dot .
确保键入了点.
in English keyboard layout in your source code. 在源代码中的英文键盘布局。 Even if the dot .
即使是点.
looks the same across languages, for example French, if you typed it in French, if you use custom (web) font in your page - and this font does not contain the dot in French, you'll see a question mark. 在语言中看起来相同,例如法语,如果你用法语键入它,如果你在页面中使用自定义(web)字体 - 并且这个字体不包含法语中的点,你会看到一个问号。
put this code where you want to pagination 将此代码放在您想要分页的位置
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts(array(
'post_type' => 'php', // You can add a custom post type if you like
'paged' => $paged,
'posts_per_page' => 2
));
add the above code before starting post loop then start your loop 在开始post循环之前添加上面的代码然后开始循环
may it works for you 它可能适合你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.