编辑默认页面以显示所有帖子,而不是最新的帖子

时间:2016-09-19 作者:Ceds

我正在尝试编辑WordPress的默认帖子页面,以便它显示所有帖子,而不是最近的10篇,但我不确定要编辑哪个文件。

我试图在wp includes/post中编辑wp\\u get\\u recent\\u posts函数。php,但没有任何效果。有人能给我指出正确的方向吗?

function wp_get_recent_posts( $args = array(), $output = ARRAY_A ) {

if ( is_numeric( $args ) ) {
    _deprecated_argument( __FUNCTION__, \'3.1\', __( \'Passing an integer number of posts is deprecated. Pass an array of arguments instead.\' ) );
    $args = array( \'numberposts\' => absint( $args ) );
}

// Set default arguments.
$defaults = array(
    \'numberposts\' => 1000, \'offset\' => 0,
    \'category\' => 0, \'orderby\' => \'post_date\',
    \'order\' => \'DESC\', \'include\' => \'\',
    \'exclude\' => \'\', \'meta_key\' => \'\',
    \'meta_value\' =>\'\', \'post_type\' => \'post\', \'post_status\' => \'draft, publish, future, pending, private\',
    \'suppress_filters\' => true
);

1 个回复
最合适的回答,由SO网友:Krystian Kupiec 整理而成

您必须将“post\\u per\\u page”设置为“-1”。将此代码添加到您的主页或索引中。php。

WP\\U查询(推荐)

$args = array(\'posts_per_page\' => -1);
$the_query = new WP_Query( $args );

if ( $the_query->have_posts() ) {
  while ( $the_query->have_posts() ) : $the_query->the_post();
    the_title();
    the_content();
  endwhile;

  /* Restore original Post Data */
  wp_reset_postdata();

} else {
  // no posts found
}
query\\u posts()方式

// Args that you pass to loop
$args = array(\'posts_per_page\' => -1);

// The Query
query_posts( $args );

// The Loop
while ( have_posts() ) : the_post();
    the_title();
    the_content();
endwhile;

// Reset Query
wp_reset_query();
或者,您可以转到仪表板->设置->阅读,并将每页的最大帖子数设置为“1000”或其他。

相关推荐

如何修改WP_INCLUDE/BLOCKS/LATEST_posts.php

我是WordPress开发的初学者,希望得到一些帮助。我在一个简单的WordPress网站上工作。基本上,用户希望在主页上显示最新的帖子。我使用了最新帖子块,并将其设置为显示整个帖子内容,现在用户不希望帖子标题链接到单个帖子页面(因为帖子的内容显示在主页上)。如何安全地修改模板文件,使其像h2标记一样使用,而不是在主题中使用的href标记。我知道您可以创建子主题并修改wp_content 文件,但我不确定如何处理中的文件wp_include. 我读到一些关于修改functions.php 但我不确定,如果