2
我想用其子頁面爲頁面添加一個數字分頁。這是分頁我會想(從引導)創建:WordPress paginate_links - 如何使用它?
<nav>
<ul class="pagination">
<li>
<a href="#" aria-label="Previous">
<span aria-hidden="true">«</span>
</a>
</li>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
<li>
<a href="#" aria-label="Next">
<span aria-hidden="true">»</span>
</a>
</li>
</ul>
</nav>
這是我的代碼:
<!-- block -->
<div class="row grid events-block">
<?php
$parent = $post->ID;
// query_posts('posts_per_page=15&post_type=page&post_parent='.$parent);
query_posts(array('posts_per_page'=>'1', 'post_type' => 'page', 'post_parent' => $parent, 'paged' => get_query_var('paged')));
while (have_posts()) : the_post();
?>
<!-- item -->
<div class="grid-item col-md-6 col-sm-6 col-xs-12 event-item">
<div class="date-box">
<?php echo $event_dates; ?>
</div>
<div class="event-item-text-box">
<div class="event-item-text-inner-box">
<h3 class="heading-item"><a href="#" target="_blank"><?php the_title(); ?></a></h3>
<p><?php the_excerpt(); ?></p>
</div>
</div>
</div>
<!-- item -->
<?php endwhile; ?>
<?php
// Reset the post to the original after loop. otherwise the current page becomes the last item from the while loop.
// https://codex.wordpress.org/Function_Reference/wp_reset_query
wp_reset_query();
?>
</div>
<!-- block -->
<?php $args = array(
'base' => '%_%',
'format' => '?paged=%#%',
'total' => 1,
'current' => 0,
'show_all' => false,
'end_size' => 1,
'mid_size' => 2,
'prev_next' => true,
'prev_text' => __('« Previous'),
'next_text' => __('Next »'),
'type' => 'plain',
'add_args' => false,
'add_fragment' => '',
'before_page_number' => '',
'after_page_number' => ''
); ?>
<?php echo paginate_links($args); ?>
但我無法得到它的工作。任何想法,我已經錯過了?
它的作品非常漂亮!謝謝您的幫助! – laukok
@ purvik7373我如何分開導航?所以我可以把一個導航欄外循環?它仍然連接到儀表板設置頁面。因爲當我在代碼中使用3並且在儀表板設置中有5個時,那麼導航顯示頁面正確,但是當僅有10個帖子並且我轉到第3頁時,那麼該頁面是空的。當我改變3中的5(所以de代碼中的相同代碼),那麼它工作正常。那麼到底發生了什麼問題? – Maanstraat