Reputation: 35
I am using the Numeric Post Navigation code in my wordpress theme. I have set Blog page show at most as 3 for 24 posts. So that the page navigation displays 8 pages. eg: 1 2 3 ... 8
. But actually the page navigation shows me 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(); ?>
Upvotes: 0
Views: 2847
Reputation: 3531
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
may it works for you
Upvotes: 0
Reputation: 4844
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).
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
Try to set your page to UTF-8, putting this:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
In your <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: …
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:
mb_internal_encoding("UTF-8");
Source : http://www.php.net/manual/en/function.mb-internal-encoding.php
Upvotes: 3
Reputation: 31829
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.
Upvotes: 0