Get all pages under a parent page, unpaginated).
<?php
$q = new WP_Query(array(
'post_parent' => $post->ID,
'post_type' => 'page',
'posts_per_page' => -1,
'orderby' => 'name',
'order' => 'ASC',
));
if ($q->have_posts()) {
echo '<ul>';
while ($q->have_posts()) {
$q->the_post();
printf('<li><a href="%s">%s</a></li>', esc_url(get_permalink()), esc_html(get_the_title()));
}
echo '</ul>';
wp_reset_postdata();
}
?>
template.php
Get all posts (paginated, on front page template only).
<?php
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$q = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => get_option('posts_per_page'),
'paged' => $paged,
));
if ($q->have_posts()) {
echo '<ul>';
while ($q->have_posts()) {
$q->the_post();
printf('<li><a href="%s">%s</a></li>', esc_url(get_permalink()), esc_html(get_the_title()));
}
echo '</ul>';
if ($q->max_num_pages > 1) {
$links = paginate_links(array(
'base' => str_replace(999999999, '%#%', esc_url(get_pagenum_link(999999999))),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('page')),
'total' => $q->max_num_pages,
'prev_text' => '<',
'next_text' => '>',
));
printf('<div class="nav-links">%s</div>', $links);
}
wp_reset_postdata();
}
?>
template.php
Get all posts (paginated, on any pages but front page).
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$q = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => get_option('posts_per_page'),
'paged' => $paged,
));
if ($q->have_posts()) {
echo '<ul>';
while ($q->have_posts()) {
$q->the_post();
printf('<li><a href="%s">%s</a></li>', esc_url(get_permalink()), esc_html(get_the_title()));
}
echo '</ul>';
if ($q->max_num_pages > 1) {
$links = paginate_links(array(
'base' => str_replace(999999999, '%#%', esc_url(get_pagenum_link(999999999))),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'total' => $q->max_num_pages,
'prev_text' => '<',
'next_text' => '>',
));
printf('<div class="nav-links">%s</div>', $links);
}
wp_reset_postdata();
}
?>
template.php