On a recent project for a client, I needed a way to have a WordPress Page contain both static content editable by the client, and dynamic content added/updated every time they made a new Post. Additionally, the dynamic content had to be paginated.
Ultimately the goal was to a have a Page with introductory text that could be edited by the client but that also served up a list of posts tagged with a certain tag. Like so:
Initially the concept was easy enough—create a new Page with multiple loops. The first loop would be the main query that pulled the static content while a secondary, custom loop query pulled posts with a specific tag.
The challenge lay in the fact that the static content would always be one page long, whereas the dynamic content might eventually grow into a really long list of posts that would need to be paginated.
So how do we go about creating a paging system that would move through the dynamically‐generated list of posts? By re‐defining the
$wp_query is the global variable that receives the parameters for a WordPress Page/Post query. Once it gets this information, it attempts to pull the appropriate content from your data base. If you’re calling a WordPress Page, it will show the content from the Page (the text/images you enter in the Page editor when you create a new Page). If you’re calling a Post, it will pull the information for that post (or posts).
$wp_query receives this information from the WP_Query Class (WP v2.0+). The Codex Page on the
WP_Query Class goes into detail on how the WP_Query Class functions, but the short of it is that this Class is the magic that makes the content appear on your blog, whether that content is in a Post or in a Page.