我正在嘗試將我的靜態主頁上的分頁工作與wordpress集成。我遇到的問題是,當我點擊頁面上的「舊條目」按鈕時,它會轉到?paged = 2頁面,但仍顯示前10個帖子。就像在第一頁上一樣。靜態主頁上的Wordpress分頁
我知道代碼在某種程度上可行,因爲我將($the_query->max_num_pages > 1)
更改爲2並進入頁面,並使用「較新條目」按鈕顯示第二頁的內容。
我只是不能讓它自動做到這一點。
我用這個人教程如何設置它 http://callmenick.com/post/custom-wordpress-loop-with-pagination
,這裏是我的代碼
<?php
// set up or arguments for our custom query
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$query_args = array(
'post_type' => 'post',
'paged' => $paged
);
// create a new instance of WP_Query
$the_query = new WP_Query($query_args);
?>
<?php if ($the_query->have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); // run the loop ?>
<article>
<h1><?php echo the_title(); ?></h1>
<div class="excerpt">
<?php the_excerpt(); ?>
</div>
</article>
<?php endwhile; ?>
<?php if ($the_query->max_num_pages > 1) { // check if the max number of pages is greater than 1 ?>
<nav class="prev-next-posts">
<div class="prev-posts-link">
<?php echo get_next_posts_link('Older Entries', $the_query->max_num_pages); // display older posts link ?>
</div>
<div class="next-posts-link">
<?php echo get_previous_posts_link('Newer Entries'); // display newer posts link ?>
</div>
</nav>
<?php } ?>
<?php else: ?>
<article>
<h1>Sorry...</h1>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
</article>
<?php endif; ?>
網站(臨時)在這裏可以看到http://auroraservers.org/MainSite/Index.php
所以你可以看到它是什麼這樣做。
謝謝你的幫助!我一直在試圖解決這個問題一天以上,所以我希望它不會太麻煩。
歡迎SO,3253191.請儘量只使用相關的標籤爲您的問題。我來自'CSS'問題堆棧的問題,它與'CSS'無關。 –
對不起,我一整天都在做些東西,並且把我最近的工作放在了頭頂。不會再發生!我承諾! – Forrest