Happy Holidays everyone! I hope you can help me with this 'little' problem I'm having :)
I am using a child theme based on Elara which displays the posts feed in different formats on the front page and on the archive pages. The main difference is that on the front page the design best suits 8 posts while on the archive pages it best fits 10 posts before navigation.
However, there is no option to specify the different limits. As far as I can tell the feed is controlled by this:
<?php
/**
* The loop / blog feed
*
* @package elara
*/
?>
<div id="blog-feed" class="section-feed row">
<?php
/**
* The loop
*
* For covering all customizer options from above, take a look at elara's feed.php
*/
if ( have_posts() ) : while ( have_posts() ) : the_post();
get_template_part( 'content', get_post_format() );
endwhile; endif;
?>
</div><!-- section-feed row -->
Then the content part of the code is this:
<?php
/**
* Main template for displaying a post within a feed
*
* @package elara
*/
$elara_class = elara_set_feed_post_class(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class( 'entry matcheight ' . esc_attr( $elara_class ) ); ?>>
<?php elara_entry_thumbnail( 'elara-archive', true ); ?>
<footer class="entry-meta">
<div>
<?php elara_entry_categories(); ?>
<?php elara_entry_separator( 'categories-date' ); ?>
<?php elara_entry_date(); ?>
</div>
<div>
<?php elara_entry_author(); ?>
<?php elara_entry_separator( 'author-comments' ); ?>
<?php elara_entry_comments_link(); ?>
</div>
</footer>
<?php elara_entry_title(); ?>
<?php elara_feed_entry_excerpt(); ?>
<?php
/**
* Get video modal for video post format
*/
get_template_part( 'parts/entry', 'video-modal' );
?>
</article><!-- #post-<?php the_ID(); ?> -->
So, my question is: can you help me customize it so the frontpage displays 8 posts before prev/next page navigation controls while the archive pages display 10 posts?
Happy Holidays everyone! I hope you can help me with this 'little' problem I'm having :)
I am using a child theme based on Elara which displays the posts feed in different formats on the front page and on the archive pages. The main difference is that on the front page the design best suits 8 posts while on the archive pages it best fits 10 posts before navigation.
However, there is no option to specify the different limits. As far as I can tell the feed is controlled by this:
<?php
/**
* The loop / blog feed
*
* @package elara
*/
?>
<div id="blog-feed" class="section-feed row">
<?php
/**
* The loop
*
* For covering all customizer options from above, take a look at elara's feed.php
*/
if ( have_posts() ) : while ( have_posts() ) : the_post();
get_template_part( 'content', get_post_format() );
endwhile; endif;
?>
</div><!-- section-feed row -->
Then the content part of the code is this:
<?php
/**
* Main template for displaying a post within a feed
*
* @package elara
*/
$elara_class = elara_set_feed_post_class(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class( 'entry matcheight ' . esc_attr( $elara_class ) ); ?>>
<?php elara_entry_thumbnail( 'elara-archive', true ); ?>
<footer class="entry-meta">
<div>
<?php elara_entry_categories(); ?>
<?php elara_entry_separator( 'categories-date' ); ?>
<?php elara_entry_date(); ?>
</div>
<div>
<?php elara_entry_author(); ?>
<?php elara_entry_separator( 'author-comments' ); ?>
<?php elara_entry_comments_link(); ?>
</div>
</footer>
<?php elara_entry_title(); ?>
<?php elara_feed_entry_excerpt(); ?>
<?php
/**
* Get video modal for video post format
*/
get_template_part( 'parts/entry', 'video-modal' );
?>
</article><!-- #post-<?php the_ID(); ?> -->
So, my question is: can you help me customize it so the frontpage displays 8 posts before prev/next page navigation controls while the archive pages display 10 posts?
OK, so this theme uses global $wp_query
to print these posts. It makes it pretty easy to change the number of posts... All you have to do is to use pre_get_posts
action and change query params.
function my_change_number_of_posts( $query ) {
if ( ! is_admin() && $query->is_main_query() ) {
if ( is_home() ) { // change only for home page
$query->set( 'posts_per_page', 8 );
}
}
}
add_action( 'pre_get_posts', 'my_change_number_of_posts' );
Of course you can modify the conditions in that action, to achieve exactly what you need.
WP_Query
utilizingposts_per_page
parameter. – Max Yudin Commented Dec 25, 2018 at 10:44