Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this questionI am using this loop and instead of getting my posts(blogs) i am getting pagetitle in my case Home and Homepage content
<?php
while(have_posts()) {
the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<hr>
<?php }
?>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this questionI am using this loop and instead of getting my posts(blogs) i am getting pagetitle in my case Home and Homepage content
<?php
while(have_posts()) {
the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<hr>
<?php }
?>
I'm not 100% sure what you're trying to do with this.
Out of the Box, WordPres allows you to set your home page as either a static page, or a blog. If you choose blog, it will automatically output title and content for you.
If you're trying to customize a static home page, then you'll need to add a piece with arguments, like they've been saying there in the comments.
<?php
$args = [
'post_type' => 'posts', // you can also use custom post types here
'posts_per_page' => '10', // how many I want to display
'post_status' => 'publish', // I only want published posts to appear
];
// The Query.
$the_query = new WP_Query( $args );
// The Loop.
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
} ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<hr>
<?php endif;
wp_reset_postdata();
}
?>
functions.php
, a plugin,...? Please edit your question to provide more context. – Pat J Commented Aug 16, 2019 at 18:46