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 trial

WordPress One Page WordPress Site

Brandon Powell
Brandon Powell
663 Points

One 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

you 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' ); ?>

you 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.

you 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
Brandon Powell
663 Points

So the website didn't help have no idea why this not work in Backend

I'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
Brandon Powell
663 Points

ok thank you do you have an skype or google hangout want screenshare so you know what talk about.

Awesome. so everything is working? you should go to the DC WP meet up, it's at a place called chief. Great meet up!!

in the future think about using git, if not already. version control works wonders.

Brandon Powell
Brandon Powell
663 Points

Yes 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.

did you get things working?

Brandon Powell
Brandon Powell
663 Points

No couldn't find any on internet to help me figure it out

I 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
Brandon Powell
663 Points

I have remove it from the modules folder now want next step https://gyazo.com/7e1df5c57ec26db5f27d01fe2221364d

test it. does it work.

Brandon Powell
Brandon Powell
663 Points

I still don't see the template pages in the backend of wordpress

have you reviewed this:

get_template_part()

your template pages need to be in the theme folder. try taking them out of the sub folder.

Brandon Powell
Brandon Powell
663 Points

Hey 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
Brandon Powell
663 Points

I'm going to upload my code to github could take look at really quick please.

sure.

I 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
Brandon Powell
663 Points

Did you get the Mishkin