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

如何在WordPress的front-page.php中调用About页面并保留Blog模块

How to Add Your About Page Content to the Top of front-page.php (Without Breaking Blog Styling)

Absolutely you can integrate your About page content above your blog section on the homepage—this is a common customization, and it’s totally doable without messing up your existing blog layout. Here’s a step-by-step breakdown:

1. Fetch and Output the About Page Content

First, you’ll need to pull the content from your About page and render it in front-page.php, right above your existing blog loop.

You can target the About page either by its slug (e.g., about) or page ID (find this in the WordPress admin when editing the About page—look for post=123 in the URL bar). Here’s a clean code snippet to add:

// Add this BEFORE your blog loop code in front-page.php
$about_page = get_post( get_page_by_path( 'about' ) ); // Uses page slug 'about'
// If you prefer using page ID, replace the line above with:
// $about_page = get_post( 123 ); // Replace 123 with your About page ID

if ( $about_page ) {
    // Wrap the content in a custom div for easy styling
    echo '<div class="home-about-section">';
        // Apply WordPress content filters (so shortcodes, paragraphs, etc. work)
        echo apply_filters( 'the_content', $about_page->post_content );
    echo '</div>';
}

2. Style the About Section to Match Your Theme

To make sure the About content fits seamlessly above your blog, add some custom CSS (either in your theme’s Customizer > Additional CSS or child theme’s style.css):

.home-about-section {
    margin-bottom: 3rem; /* Add space between About content and blog posts */
    padding: 1.5rem;
    /* Match your theme's existing typography and colors here */
    color: var(--text-color); /* Use your theme's CSS variables if available */
    line-height: 1.6;
}

This ensures the About section doesn’t clash with your blog’s styling and maintains a consistent look.

3. Keep Your Blog Section Intact

As long as you leave your existing blog loop code (the part that starts with while ( have_posts() ) : the_post(); and its surrounding markup) untouched, your blog section will retain all its original styling and functionality. You’re just inserting new content above it—no changes needed to the blog code itself.

Quick Notes:

  • Use a Child Theme: Always modify front-page.php in a child theme instead of your parent theme. This way, your changes won’t get overwritten when the theme updates.
  • Block Themes?: If you’re using a block-based theme (like Twenty Twenty-Three), you might need to use the Site Editor instead of editing front-page.php directly. But for traditional PHP themes, this method works perfectly.
  • Custom Fields/Elements: If your About page has custom fields or special template elements (like a hero image), you can extend the code to pull those in using get_post_meta() or other WordPress functions.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.08 20:22:40