index.php in WordPress Themes — a practical guide to WordPress index.php theme with clear examples you can reuse in real projects.
WordPress Theme Development Series (10/96). Prefer one article? Read the complete WordPress theme development tutorial.
Short description
`index.php` is mandatory for classic themes and is the last fallback in the template hierarchy.
Basic index.php
<?php get_header(); ?>
<main>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article <?php post_class(); ?>>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
</article>
<?php endwhile; else : ?>
<p><?php esc_html_e('No posts found.', 'acme-theme'); ?></p>
<?php endif; ?>
</main>
<?php get_footer(); ?>