WordPress Tip #1 – Page Content on the Posts Page
If you’ve used WordPress a fair bit, you’re probably familiar with the practice of using a ‘static page’ as your home page, and specifying another page to act as your ‘posts page’ (which displays a list of your posts).
If you don’t know what I’m talking about, this WordPress Codex article explains it clearly.
One important point that the above-mentioned codex article emphasises is ‘DO NOT add content to the Blog Page. Leave it blank. Any content here will be ignored’
This means that any content you add to your ‘posts page’ will not show up on the published page. It will only show the list of posts.
This has frustrated me for years, as I often want to include a sort of introduction at the top of the blog, and until recently I have resorted to hard-coding this into the theme.
However, I recently stumbled upon the following solution, which allows the contents of the ‘post page’ to be output as well as the list of posts.
Just add the following code to your index.php file in your theme directory:
<?php if ( 'page' == get_option('show_on_front') && get_option('page_for_posts') && is_home() ) : the_post(); $page_for_posts_id = get_option('page_for_posts'); setup_postdata(get_page($page_for_posts_id)); ?> <div id="post-<?php the_ID(); ?>" class="page"> <div class="entry-content"> <?php the_content(); ?> <?php edit_post_link('Edit', '', '', $page_for_posts_id); ?> </div> </div> <?php rewind_posts(); endif; ?>
See our articles page for an example. The introductory text above the posts list comes from the WordPress page.