How to show content on page with multiple loops?
-
I’ve been searching for an answer to this for hours now. Hope someone can help…
I’ve created a three column site: the left and right sidebars each contain a different loop that shows posts from specific categories.
The main content appears in the middle and is entered via the page content section of WordPress.
The problem I’m having is that after trying various coding to add the page content to the middle column, my pages instead keep showing the content of one of the posts (the most recent post, I believe). I got around this on the homepage (id=2) by adding the following code:
<?php $post_id = 2; $queried_post = get_post($post_id); echo $queried_post->post_content; ?>
However, I need this to work on all of my pages. I could create a separate page template for each page, or slightly less unwieldy, create a long set of conditionals. Either way won’t work very well; I want to have one simple page template that applies for all pages. Two questions:
1) Most importantly, how do I make the $post_id assume the value of the current page, displaying only the appropriate page content (and not the content of any of the posts)? That is, rather than having to enter $post_id = 2, 3,4, 5, etc, on separate page templates, is there some way to simply code this so that the system shows only the right content?
2) Also, for my own curiosity’s sake, why does the system return a post’s content, rather than the page content when I use the_content? I know it has something to do with the nature of the loop, but don’t know what.
Thanks for any help you can provide.
- The topic ‘How to show content on page with multiple loops?’ is closed to new replies.