Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBrandon Powell
663 PointsOne Page Wordpress Site
I'm working on one-page WordPress theme having some trouble with trying to link all the page to my home page but I one thing I have a custom page and want to make more customs pages so I can style why that want my one-page site to look like. I have done everything right with the video and still doesn't want to work for me.
<?php /**
- Template Name: One Page Site */
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
$args = array(
'post_type' => 'page',
'order' => 'ASC'
);
$the_query = new WP_Query( $args );
?>
<?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php get_template_part( 'content', 'page', 'page-about'); ?>
<?php endwhile; endif; ?>
</main><!-- #main -->
</div><!-- #primary -->
<?php get_footer();
7 Answers
Jacob Mishkin
23,118 Pointsyou should review this code:
Using with theme subfolders
To use this function with subfolders in your theme directory, simply prepend the folder name before the slug. For example, if you have a folder called “partials” in your theme directory and a template part called “content-page.php” in that sub-folder, you would use get_template_part() like this:
1
<?php get_template_part( 'partials/content', 'page' ); ?>
Jacob Mishkin
23,118 Pointsyou are really close on this one, One way to go about it using a modular approach to the site, like so:
<?php
/**
* Template Name: Home Page
*/
?>
<?php while (have_posts()) : the_post(); ?>
<?php get_template_part('templates/page', 'header'); ?>
<?php get_template_part('templates/modules/content', 'page-accordion'); ?>
<?php get_template_part('templates/modules/content', 'page-cards'); ?>
<?php get_template_part('templates/modules/content', 'page-bulletpoints'); ?>
<?php get_template_part('templates/modules/content', 'page-services'); ?>
<?php get_template_part('templates/page', 'footer'); ?>
<?php endwhile; ?>
This is an example home page, where I created a Home template and a folder called modules for the sections of the home page, then used the get_template_part() function to call the templates into one page. There are manny ways to go about it, but I find this approach great in that I can break down each section and have it easily added to the home page.
You do not need to use the if statement for this, the while loop will be enough to loop though each template part and add it to the page. if you need more help please let us know.
Jacob Mishkin
23,118 Pointsyou mean that in the backend(dashboard) when you go to a page you can not select the template that you made for them?
is there any custom templates that you made?
Brandon Powell
663 PointsSo the website didn't help have no idea why this not work in Backend
Jacob Mishkin
23,118 PointsI'm busy right now, but I will take a loop at it either tonight or tomorrow in the morning. Sorry for the delay.
Brandon Powell
663 Pointsok thank you do you have an skype or google hangout want screenshare so you know what talk about.
Jacob Mishkin
23,118 PointsAwesome. so everything is working? you should go to the DC WP meet up, it's at a place called chief. Great meet up!!
Jacob Mishkin
23,118 Pointsin the future think about using git, if not already. version control works wonders.
Brandon Powell
663 PointsYes I have saw the one-page video on threehouse that where I learn how to do first time. I got with with other project. Are you talk about two calls get_header(); and get_footer(); calling.
Jacob Mishkin
23,118 Pointsdid you get things working?
Brandon Powell
663 PointsNo couldn't find any on internet to help me figure it out
Jacob Mishkin
23,118 PointsI saw your photos, first let take out the header and footer from the modules page. If you are using my style to add templates to the page, the header and footer are inside the templates folder not the modules folder.
Brandon Powell
663 PointsI have remove it from the modules folder now want next step https://gyazo.com/7e1df5c57ec26db5f27d01fe2221364d
Jacob Mishkin
23,118 Pointstest it. does it work.
Brandon Powell
663 PointsNo does not work
Brandon Powell
663 PointsI still don't see the template pages in the backend of wordpress
Jacob Mishkin
23,118 Pointshave you reviewed this:
Jacob Mishkin
23,118 Pointsyour template pages need to be in the theme folder. try taking them out of the sub folder.
Brandon Powell
663 PointsHey Mishkin, here the link to the repo if does not work might have to send you invite https://brandonpowell@bitbucket.org/brandonpowell/mrgodinabeta.git
Brandon Powell
663 PointsI'm going to upload my code to github could take look at really quick please.
Jacob Mishkin
23,118 Pointssure.
Jacob Mishkin
23,118 PointsI receive an 404 then trying to see your bitbucket account. I would suggest you revisit the tutorial made by Zac, and if you need more help, then find some videos on youTube.
Brandon Powell
663 PointsDid you get the Mishkin