Answer the question
In order to leave comments, you need to log in
How to display posts of only this author in author.php?
Good afternoon.
The question is this.
If I draw a conclusion through
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
, then everything works as it should. <?php if (have_posts()) : ?>
<?php query_posts('posts_per_page=5'); ?>
<?php while (have_posts()) : the_post(); ?>
, then the posts of all authors are displayed. query_posts
, maybe there is some way? Answer the question
In order to leave comments, you need to log in
Withdraw through
And in functions.php add:
function author_per_page( $query ) {
if( is_author() && !is_admin() && $query->is_main_query() ) {
$query->set( 'posts_per_page', 5 );
}
add_action( 'pre_get_posts', 'author_per_page' );
There is an opinion that the good old query_posts should never be used to avoid problems in the future.
Use WP_Query where you need it and you'll be fine.
For example, authors can be displayed like this:
or so
$query = new WP_Query( 'author_name=KrutoiAvtor' );
if you use query_posts, then you need to "add" to what is already there, and you redefine the main loop.
global $wp_query;
query_posts(
array_merge( // склеиваем массивы
$wp_query->query, // это массив базового запроса текущей страницы
array('posts_per_page' => 5) // это параметры который добавили мы
)
);
// Дальше цикл
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question