Answer the question
In order to leave comments, you need to log in
Question about cycles in wordpress?
Hello. Can you explain why the list of posts is not displayed on the main page. underscores theme. What I've done ; I took the page.php template file, duplicated it, renamed it to front-page.php, created the
"Home" page, inserted the layout there, everything works.
In the reading settings, I specified the static page "Home".
Got the cycle code
<div id="primary" class="content-area">
<main id="main" class="site-main">
<?php
while ( have_posts() ) :
the_post();
get_template_part( 'template-parts/content', 'page' );
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
endwhile; // End of the loop.
?>
</main><!-- #main -->
</div><!-- #primary -->
Answer the question
In order to leave comments, you need to log in
Hello!
About the template name...
front-page.php means a static page,
home.php means a block with the latest posts.
In this code, content is displayed inside the loop, for the page template-parts/content, page:
<?php
while ( have_posts() ) :
the_post();
get_template_part( 'template-parts/content', 'page' );
endwhile; // End of the loop.
?>
// задаем нужные нам критерии выборки данных из БД
$args = array(
'posts_per_page' => 5,
);
$query = new WP_Query( $args );
// Цикл
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
} else {
// Постов не найдено
}
/* Возвращаем оригинальные данные поста. Сбрасываем $post. */
wp_reset_postdata();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question