我前段时间使用代码添加了一个页面导航到客户端网站:
<?php if ($paged > 1) { ?>
<nav id="nav-posts">
<?php
global $wp_query;
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
?>
</nav>
<?php } else { ?>
这个工作正常,直到我将Wordpress的版本更新为4,现在每次我点击进入新页面时它都没有重定向,而是只是停留在同一页面上,即使url指向{{3 }}
可以帮忙吗?
完整代码:
<?php
/*
Template Name: Runners Template
*/
get_header();
?>
<table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><img src="../../../images/blank_middle/blank_middle_01.jpg" width="57" height="20"></td>
<td><img src="../../../images/blank_middle/blank_middle_02.jpg" width="886" height="20"></td>
<td><img src="../../../images/blank_middle/blank_middle_03.jpg" width="57" height="20"></td>
</tr>
<tr>
<td background="../../../images/blank_middle/blank_middle_04.jpg"><img src="../../../images/spacer.gif" width="57" height="416" /></td>
<td valign="top" background="../../../images/blank_middle/blank_middle_05.jpg"><table width="886" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="../../../images/spacer.gif" width="30" height="1" /></td>
<td><img src="../../../images/spacer.gif" width="826" height="1" /></td>
<td><img src="../../../images/spacer.gif" width="30" height="1" /></td>
</tr>
<tr>
<td><img src="../../../images/spacer.gif" width="30" height="10" /></td>
<td align="left">
<div id="content" class="narrowcolumn" role="main">
<?php if (have_posts()) : ?>
<div class="navigation">
<div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
<div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
</div>
<h2 class="pagetitle"><?php echo get_the_title(); ?></h2>
<?php echo do_shortcode( '[searchandfilter id="2706"]' ); ?>
<?php echo do_shortcode( '[searchandfilter id="2706" show="results"]' ); ?>
<a class="reset" href="#" onclick="$('select').each(function() { this.selectedIndex = 0 });">Reset search</a>
<?php // Display blog posts on any page @ http://m0n.co/l
$temp = $wp_query; $wp_query= null;
$wp_query = new WP_Query(); $wp_query->query('cat=24' . '&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<div <?php post_class() ?>>
<h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
<div class="entry">
<?php the_content() ?>
</div>
<br>
</div>
<?php endwhile; ?>
<?php if ($paged > 1) { ?>
<nav id="nav-posts">
<?php
global $wp_query;
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
?>
</nav>
<?php } else { ?>
<nav id="nav-posts">
<?php
global $wp_query;
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
?>
</nav>
<?php } ?>
<?php wp_reset_postdata(); ?>
<?php else :
if ( is_category() ) { // If this is a category archive
printf("<h2 class='center'>Sorry, but there aren't any posts in the %s category yet.</h2>", single_cat_title('',false));
} else if ( is_date() ) { // If this is a date archive
echo("<h2>Sorry, but there aren't any posts with this date.</h2>");
} else if ( is_author() ) { // If this is a category archive
$userdata = get_userdatabylogin(get_query_var('author_name'));
printf("<h2 class='center'>Sorry, but there aren't any posts by %s yet.</h2>", $userdata->display_name);
} else {
echo("<h2 class='center'>No posts found.</h2>");
}
get_search_form();
endif;
?>
</div>
</td>
<td><img src="../../../images/spacer.gif" width="30" height="10" /></td>
</tr>
</table></td>
<td background="../../../images/blank_middle/blank_middle_06.jpg"><img src="../../../images/spacer.gif" width="57" height="416" /></td>
</tr>
</table>
<?php get_footer(); ?>
答案 0 :(得分:3)
此问题的解决方案是使用replace。
$big = 999999999; // need an unlikely integer
$search_for = array( $big, '#038;' );
$replace_with = array( '%#%', '&' );
echo paginate_links( array(
'base' => str_replace( $search_for, $replace_with, esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
答案 1 :(得分:0)
编辑:
$search_for = array( $big, '#038;', '&&' );
$replace_with = array( '%#%', '&', '&' );