admin管理员组文章数量:1130349
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?
Share Improve this question edited Dec 25, 2018 at 11:45 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Dec 25, 2018 at 10:11 kr3t3nkr3t3n 1031 bronze badge 3 |1 Answer
Reset to default 1OK, 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.
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?
Share Improve this question edited Dec 25, 2018 at 11:45 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Dec 25, 2018 at 10:11 kr3t3nkr3t3n 1031 bronze badge 3-
Create your own loop for either front or archive using
WP_Queryutilizingposts_per_pageparameter. – Max Yudin Commented Dec 25, 2018 at 10:44 - @MaxYudin, I thought that I would have to create my own loop, however my knowledge is quite limited and am unsure how to make it specific to the archive pages and not the frontpage. Also, would I do this on the same .php file (the feed.php)? – kr3t3n Commented Dec 25, 2018 at 11:14
- You don't have to create loop - just use pre_get_posts filter action... – Krzysiek Dróżdż Commented Dec 25, 2018 at 11:16
1 Answer
Reset to default 1OK, 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 queryPosts feed number of posts
版权声明:本文标题:wp query - Posts feed number of posts 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749069377a2311335.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


WP_Queryutilizingposts_per_pageparameter. – Max Yudin Commented Dec 25, 2018 at 10:44