Closed. This question needs details or clarity. It is not currently accepting answers.admin管理员组文章数量:1415673
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 }
?>
Share
Improve this question
edited Aug 17, 2019 at 12:19
user173633
asked Aug 16, 2019 at 18:27
user173633user173633
11 bronze badge
4
|
1 Answer
Reset to default 1I'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();
}
?>
本文标签: phpWhy my loop isn39t working
版权声明:本文标题:php - Why my loop isn't working? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745235749a2649029.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
functions.php
, a plugin,...? Please edit your question to provide more context. – Pat J Commented Aug 16, 2019 at 18:46