自定义分类分页 Wordpress
Custom category pagination Wordpress
我在 WordPress 的自定义模板页面上有一个自定义循环,它显示来自特定类别的帖子。这一切都很好,并显示了我需要的一切,但我最终需要添加一些分页。由于这是一个自定义循环,因此本机 WP 'Blog pages show at most' 似乎不起作用。有没有办法为我的自定义循环添加分页?
<?php
// add journal posts to the journal page
query_posts( array ( 'category_name' => 'journals', 'posts_per_page' => -1 ) );
?>
<?php
// The Loop
while ( have_posts() ) : the_post();
echo '<div class="journal-posts">';
echo '<h2 class="entry-title">';
echo '<div><a href="'. esc_url( get_permalink() ) . '">' . sprintf(__( get_the_title() )) . '</a> <img src="http://localhost/website.co.uk/wp-content/themes/themename/images/icons/icon.png" alt="Icon Stuff"/></div>';
echo '</h2>';
echo '<span class="entry-meta">Posted on ';
echo '<span class="date-link">';
the_date();
echo '</span>';
echo ' by ';
echo '<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>';
echo '</span>';
the_content();
echo '</div>';
endwhile; ?>
<?php
// Reset Query
wp_reset_query();
?>
我为这个网站调用了三个单独的类别,因此我需要在每个页面上都有这个自定义循环。除非有更好的方法吗?
提前致谢!
我认为关键是在查询中设置/使用 $paged
属性,如下所示:
$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
$query_args = array(
'post_type' => 'post',
'category_name' => 'tutorials',
'posts_per_page' => 5,
'paged' => $paged
);
这取自 this article and in this question。
我在 WordPress 的自定义模板页面上有一个自定义循环,它显示来自特定类别的帖子。这一切都很好,并显示了我需要的一切,但我最终需要添加一些分页。由于这是一个自定义循环,因此本机 WP 'Blog pages show at most' 似乎不起作用。有没有办法为我的自定义循环添加分页?
<?php
// add journal posts to the journal page
query_posts( array ( 'category_name' => 'journals', 'posts_per_page' => -1 ) );
?>
<?php
// The Loop
while ( have_posts() ) : the_post();
echo '<div class="journal-posts">';
echo '<h2 class="entry-title">';
echo '<div><a href="'. esc_url( get_permalink() ) . '">' . sprintf(__( get_the_title() )) . '</a> <img src="http://localhost/website.co.uk/wp-content/themes/themename/images/icons/icon.png" alt="Icon Stuff"/></div>';
echo '</h2>';
echo '<span class="entry-meta">Posted on ';
echo '<span class="date-link">';
the_date();
echo '</span>';
echo ' by ';
echo '<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>';
echo '</span>';
the_content();
echo '</div>';
endwhile; ?>
<?php
// Reset Query
wp_reset_query();
?>
我为这个网站调用了三个单独的类别,因此我需要在每个页面上都有这个自定义循环。除非有更好的方法吗?
提前致谢!
我认为关键是在查询中设置/使用 $paged
属性,如下所示:
$paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
$query_args = array(
'post_type' => 'post',
'category_name' => 'tutorials',
'posts_per_page' => 5,
'paged' => $paged
);
这取自 this article and in this question。