In my WordPress site, I made a custom page template, which contained a custom query [using WP_Query()
]. With that query, I can perfectly get the posts of a certain category. But I want to show the page contents along with the queried posts.
Thing will be like:
—————————
Page Heading
page contents
Queried Post Heading
queried post contents
—————————
- What can I do?
I’m using two loops. First loop is to show the page content, and the second loop is to show the queried post contents. I commented into the codes where necessary. I emphasized into the loops, as Deckster0 said in WordPress support that,
the_content()
works only inside a WordPress Loop. I’m placing these code into a my own template:Two loops is common to do this, but a bit overdosed.
Every post or page gives you the super-variable
$post
. Ever wondered why yourget_post_meta()
works with a simple$post->ID
😉 ?So, before you start the WP_Query() that gets your listed posts, you can access the current page-/post-data with
$post->ID
,$post->post_content
,$post->guid
and so on.In the loop, this variable gets filled by the looped post. To save it for later, you can either make a new variable
or call
after the listing. The last function should be called anyway to ensure that the data in your sidebar is the right for the current page/post.