如何在WordPress Oria主题首页网格与分页下方添加文章?
Hey there! Let's get that extra post showing up below your homepage grid and pagination. I'll break this down into simple, non-technical steps since you mentioned you're not a tech expert.
Why copying single post code didn't work
The homepage uses a loop to display your regular blog posts, and just pasting single post template code doesn't tell WordPress which specific post to load—plus, the placement might not have been right in the template structure.
Step 1: Get your post's ID
First, you need the unique ID of the post you want to add:
- Go to your WordPress dashboard, edit the post you want to display
- Look at the browser's address bar—you'll see something like
...post.php?post=123&action=edit - The number after
post=(in this example, 123) is your post's ID. Write that down!
Step 2: Modify your index.php file
Open the index.php code you shared, and add this snippet right after the pagination line (<?php the_posts_navigation(); ?>) and before the <?php else : ?> line. Here's the full modified code with the new section highlighted:
<?php get_header(); ?> <div id="primary" class="content-area"> <main id="main" class="site-main" role="main"> <?php if ( have_posts() ) : ?> <?php /* Start the Loop */ ?> <?php while ( have_posts() ) : the_post(); ?> <?php get_template_part( 'template-parts/content', get_post_format() ); ?> <?php endwhile; ?> <?php the_posts_navigation(); ?> <!-- BEGIN: Added extra post --> <?php // Replace 123 with YOUR post's ID from Step 1 $extra_post = get_post(123); if ($extra_post) { setup_postdata($extra_post); get_template_part('template-parts/content', get_post_format()); wp_reset_postdata(); // Reset to avoid breaking other content } ?> <!-- END: Added extra post --> <?php else : ?> <?php get_template_part( 'template-parts/content', 'none' ); ?> <?php endif; ?> </main><!-- #main --> </div><!-- #primary -->
What this code does:
get_post(123): Fetches the post with your specific IDsetup_postdata($extra_post): Tells WordPress to use this post for the template partget_template_part(...): Uses the same grid-style template as your other homepage posts, so it matches the Oria theme's designwp_reset_postdata(): Resets WordPress back to the original blog post loop, so nothing else breaks
Important Notes:
- Always back up your theme files before editing: If something goes wrong, you can restore the original code easily.
- Consider using a child theme: If you edit the main Oria theme directly, your changes will be lost when the theme updates. A child theme lets you keep customizations safe—you can copy the
index.phpto your child theme folder and make edits there instead.
内容的提问来源于stack exchange,提问作者Nik.P

