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

WordPress Type主题:最新文章显完整内容其余显摘要求助

Fix: Show Full Content for the First Post, Excerpts for Others on Your Type Theme Homepage

Hey there! Since you’re solid with HTML/CSS but still getting the hang of PHP, let’s walk through a straightforward fix for this issue—no messy syntax errors, promise.

Step 1: Add a Post Counter to Your Index Loop

First, we need to track which post we’re on in the homepage loop. Open your index.php file and find the start of the WordPress loop (it’ll look like while ( have_posts() ) : the_post();). We’ll initialize a counter right before the loop, then increment it inside the loop:

<?php
// Initialize post counter BEFORE the loop
$post_count = 0;

while ( have_posts() ) : the_post();
    // Increment counter for each post
    $post_count++;
    // Load the content-list template
    get_template_part( 'content', 'list' );
endwhile;
?>

Step 2: Modify content-list.php to Show Full Content for the First Post

Next, open content-list.php and find the line where it outputs the post content (either the_excerpt() or the_content()). Replace that line with this conditional check:

<?php
// Check if we're on the homepage AND this is the first post
if ( is_front_page() && $post_count === 1 ) {
    // Show full content for the first post
    the_content();
} else {
    // Show excerpt for all other posts
    the_excerpt();
}
?>

Why This Works

  • The $post_count variable keeps track of which post we’re rendering in the loop.
  • The is_front_page() check ensures this only applies to your homepage (so pagination pages or other archive pages won’t accidentally show full content for their first post).
  • We’re using strict equality (===) to avoid any weird type mismatch issues with PHP.

Quick Notes

  • Always use a child theme: If you modify the parent theme files directly, your changes will be lost when the theme updates. Create a child theme first, then copy index.php and content-list.php into it to make your edits.
  • Troubleshooting syntax errors: If you ran into issues before, double-check that you’re wrapping PHP code in <?php ?> tags properly, and that the counter variable is initialized outside the loop (not inside).

That should do it! Your homepage’s latest post will show full content, and every other post will stick to the excerpt.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 07:08:01