You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在WordPress首页仅显示带分页的文章标题与特色图片

解决Twenty Fifteen主题首页仅显示文章标题+特色图片并带分页的方法

方法一:直接修改index.php模板(建议先备份文件)

找到你提供的index.php代码中的循环部分,将get_template_part( 'content', get_post_format() );替换为以下代码,直接输出特色图片和文章标题:

// 输出文章特色图片(带链接到文章详情)
if ( has_post_thumbnail() ) {
    echo '<div class="post-featured-image">';
    echo '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">';
    the_post_thumbnail( 'post-thumbnail' );
    echo '</a>';
    echo '</div>';
}

// 输出文章标题(带链接)
echo '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . get_the_title() . '</a></h2>';

然后在循环结束(endwhile;)之后添加分页导航代码,确保分页功能正常:

// 显示分页导航
the_posts_pagination( array(
    'mid_size' => 2,
    'prev_text' => __( '上一页', 'twentyfifteen' ),
    'next_text' => __( '下一页', 'twentyfifteen' ),
) );

方法二:使用子主题创建专属模板(推荐,避免主题更新丢失修改)

  1. 若未创建子主题,先完成Twenty Fifteen子主题的创建并启用(可参考WordPress官方文档的子主题创建流程)。
  2. 在子主题目录下新建content-home.php文件,写入以下内容:
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <?php if ( has_post_thumbnail() ) : ?>
        <div class="post-thumbnail">
            <a href="<?php esc_url( the_permalink() ); ?>" rel="bookmark">
                <?php the_post_thumbnail(); ?>
            </a>
        </div>
    <?php endif; ?>

    <header class="entry-header">
        <?php the_title( sprintf( '<h2 class="entry-title"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' ); ?>
    </header>
</article>
  1. 修改子主题的index.php文件,将循环中的get_template_part( 'content', get_post_format() );替换为:
if ( is_home() ) {
    get_template_part( 'content', 'home' );
} else {
    get_template_part( 'content', get_post_format() );
}

最后确保分页生效

进入WordPress后台,依次点击「设置」→「阅读」,在「博客页面最多显示」选项中设置每页显示的文章数量(比如10篇),保存设置后首页就会自动分页。

内容的提问来源于stack exchange,提问作者user366810

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 10:25:12