Php WordPress-';循环';若要显示所有帖子,请改为发布主页的标题

Php WordPress-';循环';若要显示所有帖子,请改为发布主页的标题,php,wordpress,Php,Wordpress,我刚开始一个wordpress教程系列,它做的第一件事就是制作一个简单的“循环”,打印所有文章的标题和描述。但当我这样做时,它会打印主页的名称和描述 <?php if ( have_posts() ) { while ( have_posts() ) { the_post(); the_title('<h2><a href="the_permalink();"','</a></h2>');

我刚开始一个wordpress教程系列,它做的第一件事就是制作一个简单的“循环”,打印所有文章的标题和描述。但当我这样做时,它会打印主页的名称和描述

<?php 
if ( have_posts() ) 
 {
  while ( have_posts() ) 
    {
        the_post(); 
        the_title('<h2><a href="the_permalink();"','</a></h2>');   
        the_content(); 
        // Post Content here
        //
    } // end while
 } // end if
?>

要在任何页面上显示wordpress帖子,您需要在WP_查询中按如下方式传递参数,然后通过对象循环它们

// The Query
$the_query = new WP_Query( array( 'post_type' => 'post','posts_per_page' => -1 ) );

// The Loop
if ( $the_query->have_posts() ) {
    echo '<ul>';
    while ( $the_query->have_posts() ) {
        $the_query->the_post();
        echo '<li>' . get_the_title() . '</li>';
    }
    echo '</ul>';
    /* Restore original Post Data */
    wp_reset_postdata();
} else {
    // no posts found
}
//查询
$the_query=new WP_query(数组('post_type'=>'post','posts_per_page'=>1));
//环路
if($the\u query->have\u posts()){
回声“
    ”; while($the\u query->have\u posts()){ $the_query->the_post(); 回显“
  • ”。获取标题(); } 回声“
”; /*恢复原始Post数据*/ wp_reset_postdata(); }否则{ //没有找到帖子 }
你把代码放在哪里了?如果你想显示所有的文章标题和内容,你应该考虑全局变量$PAST.这是整个索引文件。我在看一个视频教程,他们就能够让它工作了。好吧,这更有意义。我想知道这篇文章的信息是从哪里来的。我只是有点困惑,因为我在看一个视频教程,它不需要制作一个新的对象。实际上,默认情况下,_post将首先获取首页(通常是您的主页)信息。如果您想在主页上显示您的文章,那么您可以通过从“设置”面板将“阅读”选项更改为“博客”来实现。