0

以下是我正在尝试执行的操作:我正在尝试将我的帖子的所有摘录显示到我的blog.php页面,但它不会在blog.php页面中显示帖子,它仅适用于在index.php页面中工作。让我来解释更.....无法在索引中显示帖子

这里是我的代码:

<?php 
    while (have_posts()) : the_post(); 

    get_template_part('excerpt', get_post_format()); 

    endwhile; 
?> 

如果我把在index.php,它会显示在帖子的摘录。我也有一个名为blog.php的页面。我已将页面模板更改为blog.php文件。但是,当我将相同的代码放在上面的blog.php页面中时,它只显示页面内容,但不显示所有帖子。我该如何解决这个问题?

回答

0

OK .....我知道了,此代码的工作:

$current_page = (get_query_var('paged')) ? get_query_var('paged') : 1; // get current page number 
$args = array(
    'posts_per_page' => get_option('posts_per_page'), // the value from Settings > Reading by default 
    'paged'   => $current_page // current page 
); 
query_posts($args); 

$wp_query->is_archive = true; 
$wp_query->is_home = false; 

while(have_posts()): the_post(); 
    ?> 
    <h2><?php the_title() /* post title */ ?></h2> 
    <p><?php the_content() /* post content */ ?></p> 
    <?php 
endwhile; 

https://rudrastyh.com/wordpress/separate-blog-pages.html