I'm looking for a way on how to display only a few posts on a first page of my archive. This is my archive template — page-archive.php
, which I am using as a template to display all my posts/recipes:
<?php
get_header('archive'); ?>
<div id="primary" class="content-area blog-archive col-md-9">
<main id="main" class="site-main">
<div class="breadcrumbs-block"><?php
if ( function_exists('yoast_breadcrumb') ) {
yoast_breadcrumb( '<p id="breadcrumbs">','</p>' );
}
?>
</div>
<?php query_posts('post_type=post&post_status=publish&posts_per_page=24&paged='. get_query_var('paged')); ?>
<?php if( have_posts() ): ?>
<div class="row all-recipes-block">
<?php while( have_posts() ): the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class('col-md-4'); ?>>
<?php if ( has_post_thumbnail() ) : ?>
<a class="post-teaser" href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<div class="thumbnail-block"><?php the_post_thumbnail('regular-post-thumbnail'); ?></div>
<div class="title-block"><span class="h3 title-for-widget"><?php the_title(); ?></span></div>
</a>
<?php endif; ?>
</article>
<?php endwhile; ?>
</div>
<div class="pagination-block row">
<?php numeric_posts_nav(); ?>
</div>
<?php else: ?>
<div id="post-404" class="noposts">
<p><?php _e('None found.','example'); ?></p>
</div><!-- /#post-404 -->
<?php endif; wp_reset_query(); ?>
</main>
</div>
<?php
get_footer();
Currently I have 24 posts per page and pagination, and I would love to show only 12 posts on the first page!
This is my post navigation function:
// numeric posts navigation
function numeric_posts_nav() {
if( is_singular() )
return;
global $wp_query;
/** Stop execution if there's only 1 page */
if( $wp_query->max_num_pages <= 1 )
return;
$paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
$max = intval( $wp_query->max_num_pages );
/** Add current page to the array */
if ( $paged >= 1 )
$links[] = $paged;
/** Add the pages around the current page to the array */
if ( $paged >= 3 ) {
$links[] = $paged - 1;
$links[] = $paged - 2;
}
if ( ( $paged + 2 ) <= $max ) {
$links[] = $paged + 2;
$links[] = $paged + 1;
}
echo '<div class="pagination-navigation col-md-12"><ul class="d-flex justify-content-center">' . "\n";
Please help!
Thank you in advance!
query_posts()
in your template. Use thepre_get_posts
hook instead to modify the main query's arguments likeposts_per_page
. And by "archive template", are you referring to thearchive.php
file?page
) with the slugarchive
, right? Can you add that detail and the ones in your previous comment to your post along with the code for thenumeric_posts_nav()
function?numeric_posts_nav()
function, but i have no idea how to usepre_get_posts
vsquery_posts()
, can you please explain to me like i am 10 year old:)) What function should i use in function.php? Or i use snippet plugin, and how i call it in my case in my page template (i posted above). Sorry i know a lot about CSS and HTML, but when it comes to PHP, i have no idea, man:)