0
我發現這個自定義wordpress分頁的地方,並嘗試使用它。分頁和「查看所有」功能工作正常,但問題是與「下一個」和「前一個」功能。當點擊「下一個按鈕」時,跳到最後一頁。你能幫我調試這個代碼嗎?我對PHP並不熟悉,實際上我第一次整合到WordPress。謝謝!WordPress的自定義分頁「下一頁」不工作
function numeric_pagination ($pageCount = 9, $query = null) {
if ($query == null) {
global $wp_query;
$query = $wp_query;
}
if ($query->max_num_pages <= 1) {
return;
}
$pageStart = 1;
$paged = $query->query_vars['paged'];
// set current page if on the first page
if ($paged == null) {
$paged = 1;
}
// work out if page start is halfway through the current visible pages and if so move it accordingly
if ($paged > floor($pageCount/2)) {
$pageStart = $paged - floor($pageCount/2);
}
if ($pageStart < 1) {
$pageStart = 1;
}
// make sure page start is
if ($pageStart + $pageCount > $query->max_num_pages) {
$pageCount = $query->max_num_pages - $pageStart;
}
?>
<div id="pagination">
<?php
if ($paged != 1) {
?>
<a href="<?php echo get_pagenum_link(1); ?>" class="numbered page-number-first"><span>‹‹ <?php _e('Previous Page', 'rhinoplasty'); ?></span></a>
<?php
}
if ($pageStart > 1) {
//echo 'previous';
}
for ($p = $pageStart; $p <= $pageStart + $pageCount; $p ++) {
if ($p == $paged) {
?>
<span class="numbered page-number-<?php echo $p; ?> current-numeric-page"><?php echo $p; ?></span>
<?php } else { ?>
<a href="<?php echo get_pagenum_link($p); ?>" class="numbered page-number-<?php echo $p; ?>"><span><?php echo $p; ?></span></a>
<?php
}
}
if ($pageStart + $pageCount < $query->max_num_pages) {
//echo "last";
}
if ($paged != $query->max_num_pages) {
?>
<a href="<?php echo get_pagenum_link($query->max_num_pages); ?>" class="numbered page-number-last"><span><?php _e('Next Page', 'rhinoplasty'); ?> ››</span></a>
<?php } ?>
<?php if(!$_GET['viewall']){ ?>
<a href="<?php echo add_query_arg(array('viewall' => "true"), get_pagenum_link(1)); ?>">View All</a>
<?php } ?>
</div>
<?php
}
if (isset($_GET['viewall']))
{
function view_allposts($query) {
$query->set('posts_per_page', -1);
}
add_action('pre_get_posts', 'view_allposts');
}
謝謝普拉卡什!我需要我的頁面的「查看全部」功能。糾正我,如果我錯了,但它似乎沒有提供該功能。我非常感謝你的幫助。 –
謝謝普拉卡什!這解決了我的問題。我不知道如何「+代表」你。非常感謝! –
感謝哥們..你已經接受了我的回答:) –