Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

WordPress

David Jarrin
PLUS
David Jarrin
Courses Plus Student 11,182 Points

One-page wordpress site

I am picking up a project I put down a long time ago....probably because I got frustrated. I think once I get past this one step I should be able to continue without too much resistance (I've been known to say that before and it hasn't been true though). My problem is getting all the pages to link into one for a one page site. So far I have set the home page to static. My "one-page-site.php" file is below.

<?php 
  /*
Template Name: One-Page-Theme
*/
 get_header(); 

?>


<!-- Main jumbotron for a primary marketing message or call to action -->
    <div class="jumbotron">
      <div class="container">

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

            <?php endwhile; endif; ?>

      </div>
    </div>

    <div class="container">
      <!-- Example row of columns -->
      <div class="row">
        <div class="col-md-4">
          <h2>Heading</h2>
          <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
          <p><a class="btn btn-default" href="#" role="button">View details &raquo;</a></p>
        </div>
        <div class="col-md-4">
          <h2>Heading</h2>
          <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
          <p><a class="btn btn-default" href="#" role="button">View details &raquo;</a></p>
       </div>
        <div class="col-md-4">
          <h2>Heading</h2>
          <p>Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</p>
          <p><a class="btn btn-default" href="#" role="button">View details &raquo;</a></p>
        </div>
      </div>

<?php get_footer(); ?>

I then set my home page to have the template of one-page-theme and the pages still don't link. The other files in my site are footer.php, functions.php, header.php, index.php, menu.php and page.php. Any help would be appreciated, been trying this for awhile and need some fresh eyes, any suggestions of what the problem could be would also be appreciated as well.

1 Answer

Agustin Grube
Agustin Grube
39,278 Points

Here is the page from the course files. Try it with this code to see if it will work, then add the new code bit by bit to see if it breaks to narrow down the problem.

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

            <?php endwhile; endif; ?>

        </main><!-- #main -->
    </div><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

Also, changing classes like:

<div id="primary" class="content-area">
        <main id="main" class="site-main" role="main">

to...

<div class="jumbotron">
      <div class="container">

may cause some problems if you do not have the css to go with it.

David Jarrin
David Jarrin
Courses Plus Student 11,182 Points

Ok so I sorta got it to work by changing

<?php get_template_part( 'content', 'page' ); ?>

to

<?php get_template_part( 'page' ); ?>

now it just repeats what I have typed into the home page wordpress backend 6 times (the total number of pages I have). reading up on what the "get_template_part()" method does it looks like it accepts slug and name arguments. So I am putting in 'page' as the slug argument. When I change it to 'menu' for example (one of my page names) nothing really changes.