Development, Journal

Showing the teaser in WordPress sub-pages

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.

Standard

2 thoughts on “Showing the teaser in WordPress sub-pages

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s