我从现有主题(One Engine Theme)构建了一个wordpress主题。该网站已经推出,除了分页外,所有网站似乎都运行良好。我尝试了很多东西,却未能让它发挥作用。所有模板页面都是为了在某些时候分页,但似乎没有人工作。以下是博客页面模板的循环代码:
<?php
$newsposts = get_posts();
foreach($newsposts as $post) :
setup_postdata($post); ?>
//the html codes are added here
<?php endforeach; ?>
我想将每页的帖子设为4,并添加默认的wordpress分页功能:
<?php posts_nav_link(); ?>
这里的页面模板是blog.php,你可以看到这里的页面:www.kayodeolusoji.net/blog 非常感谢您的帮助!
答案 0 :(得分:1)
试试这个:
我在 $ args 中添加了一些'paged'atrribute与WP_Query
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$posts_per_page=4;
$args = array(
'paged' => $paged,
'posts_per_page'=>$posts_per_page
);
$newsposts = new WP_Query($args);
while($newsposts->have_posts()) :$newsposts->the_post();
echo $post->ID.'<br />';
endwhile;
wp_reset_query();
global $wp_query;
$big = 999999999;
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $newsposts->max_num_pages
) );
答案 1 :(得分:0)
<?php
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$wp_query->query('showposts=4'.'&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post();
?>
//the html codes are added here
<?php endwhile; ?>
<nav>
<?php //the pagination codes ?>
</nav>
<?php
$wp_query = null;
$wp_query = $temp; // Reset
?>