Answer the question
In order to leave comments, you need to log in
How to display posts from wordpress in index.php?
I'm just learning wordpress, some obvious things don't work out yet.
There is a landing page in which some rubles, for example "best offers", must be changed from the admin panel. I've loaded everything into a post and listed it in index.php with get_field('field_name'), but only the most recent post is displayed.
How to solve this problem and display all posts from the admin panel?
Answer the question
In order to leave comments, you need to log in
If I understand the question correctly, then you need to arrange a whole custom WP_Query query and its processing.
<?php
$args = array(
'post_type' => 'post',
'posts_per_page' => -1, // Значение «-1» выведет все записи, можно поставить целое число, чтобы ограничить вывод конкретным количеством записей.
'category_name' => 'category_1' // Здесь имя той рубрики, посты из которой вы хотите выводить.
);
$wp_query = new WP_Query( $args );
if ( $wp_query->have_posts() ) {
?>
<div><!-- здесь открываем родительский элемент -->
<?php
while ( $wp_query->have_posts() ) {
$wp_query->the_post();
$post_id = get_the_ID();
?>
<!-- произвольный вывод каждого элемента рубрики -->
<article id="post-<?php echo $post_id; ?>" <?php post_class(); ?>>
<h2><?php the_title(); ?></h2>
<section><?php the_content(); ?></section>
</article>
<?php
}
?>
</div><!-- здесь закрываем родительский элемент -->
<?php
// Обязательно сбрасываем запрос, чтобы не сломать остатки лендинга.
wp_reset_query();
}
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question