I want the CMS to have the different pages (e.g. “Careers”, “Jobs”, “Team”) with each having its own template, but then to combine them into one big scrollable page (e.g. “Our Company”) that would have a template. How would I do this?
I know there used to be a function get_page
but that’s been deprecated (and replaced with get_post
which is not the same thing), but that doesn’t retrieve the page’s template.
-
I want both the page and the template so I can output both into the main page.
-
I also want it so if someone clicks in the navigation menu to go to “Jobs” or “Team”, it will take them to that “Our Company” page, but with a querystring so I can scroll them to that part of the page
Is this possible?
First for main page template choose default template and write you global elements there. And in this template use get_template part to include pages
and in career, blog etc pages
for
“I also want it so if someone clicks in the navigation menu to go to “Jobs” or “Team”, it will take them to that “Our Company” page, but with a querystring so I can scroll them to that part of the page”
assign each pages wrapper to page slug example
<section class="<?php echo $post->post_name; ?>">
and write a function to redirect your view page link tohttp://yoursiteurl/#page-slug
EDIT
In order to get one page’s content into another use the following function:
and then create a template for the “Our company” page (like
template-our_company.php
) in which you will make a call to the function (e.g.<?php show_post('careers'); /* Shows the content of the "Careers" page using the slug. */ ?>
).So the template file should include something like this:
For your 2nd question, you need to adjust the template-our_company.php file like this:
and then in the Menu dashboard, just adjust the navigation link to something like “/our-company/#careers” etc.
EDIT 2
In order to retrieve the content of pages with specified templates in another template, you can do the following:
Create the templates (files careers.php and jobs.php) and the posts that will be using those templates
…
Then in the “parent” template, you can query the posts that have the above specified templates selected
untested code
@user3418748’s answer was a good start for me, but in my case I needed to load specific pages, and I found that just using
get_template_part()
by itself wasn’t loading any content because I was doing it outside a loop. In order to get this to work you need to first set the global$post
variable to the page/post you want to display. Here’s the function I used (replacemytemplate
with the name of your tempalte):