0

I'm trying to create a one page theme. I need all the pages created by the admin to show up on one page.

I used the following code I found in a similar question in here:

foreach ($pages as $page_data) {
    $content = apply_filters('the_content', $page_data->post_content);
    $title = $page_data->post_title;
    $slug = $page_data->post_name;
    echo "<div class='page $slug'>";
    echo "<h2>$title</h2>";
    echo $content;
    echo "</div>";
}

The problem with this code is that it does not render the page according to the template provided for that page. Is it possible to have each page rendered as they would if their URL was visited?

Which leads to my next question; once this is done, a lot of bloat must be loaded (eg. a header, menu, footer etc. for each page). Is it possible for the page template to know if it is being rendered as the "main view" / only view, or is being rendered as part of something else?

I'm quite sure this question must have been asked a million times, but I can't seem to find any answers in regard to rendering the view according to the templates, so I hope I don't baffle anyone just by asking :)

  • You might take another look at other questions as for the code you want to use, like this one. The function get_template_part is definitely a way to render your pages with according templates. You should be able to implement a distinction, what - with or without heder, footer etc - template to load based on a conditional checking for is_home or is_front_page or is_page or something else or likely some of them combined. No time for an actual answer, but I hope that gives you a little better idea. Good luck! – Nicolai Aug 30 '14 at 20:27
  • Thanks for the response, it helped me out a lot. i do have a follow up question: wordpress.stackexchange.com/questions/159724/… – Tau Sand Aug 31 '14 at 20:05
  • No problem, I have given you an answer on your question. Can you delete this one? Thanks. – Nicolai Aug 31 '14 at 20:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.