Been working on a WordPress problem that’s been vexing me for the past few weeks. Since I use WP to run the entire websites, I typically place the blog section as a separate sub-page under the website root. My site structure might look like this:

The problem that I and others were facing was that blog posts on the sub-page were showing the full post instead of the portion before the <!--more--> tag.

The function get_the_content (called within the_content function) will only show the post teaser if it’s not a single or non-permalink page. The solution involves making WordPress think that the sub-page is a non-permalink page. I accomplished this by setting the global $more variable to 0 in my page template. For example:


Now, when I execute the WordPress Loop in this sub-page, the posts that are displayed correctly show the teaser and not the entire post. Developers may want to store the current value of the $more variable in case other functions/plugins rely it.

2 responses to “Showing the teaser in WordPress sub-pages”

  1. syndromes Avatar
    syndromes

    You big tease you ;)

  2. David Golden Avatar
    David Golden

    Good to hear you using wordpress. I just moved there as well, and will likely be asking you for help :-)

Leave a reply to David Golden Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.