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

Brett Smith
Brett Smith
4,261 Points

One Page Wordpress Site using ACF

I'm new to Wordpress and I recently completed the One Page Wordpress workshop and I'm now trying to create my own one pager.

How can I create a one page site while using the Advanced Custom Fields plugin? If I'm using ACF I can't use the same template file (like the one-page-site.php file used in the workshop) for every page.

3 Answers

-- "If I'm using ACF I can't use the same template file (like the one-page-site.php file used in the workshop) for every page."

You can.

You can tell the ACF fields to only appear on the specific page that you want, those pages may all still use the same single template file, but as far as WordPress is concerned, they're all different pages and will be able to be treated that way by Advanced Custom Fields.

Brett Smith
Brett Smith
4,261 Points

That makes sense but how can I use a CSS grid on the different fields? I'll have to use the_content() rather than the_field() right?

I'm not totally sure what you mean. Do you have any code?

Brett Smith
Brett Smith
4,261 Points
<?php 
/*

    Template Name: Porfolio Page

*/
?>
<?php get_header(); ?>
</section>
<?php 

    $args = array(
        'post_type' => 'portfolio'
    );

    $the_query = new WP_Query( $args );

?>

<?php if ( have_posts () ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

    <section class="portfolio">
      <div class="hero" style="background-image:url('<?php the_field( 'hero' ); ?>');height:400px;"></div>
      <div class="row">
        <div class="large-12 large-centered columns">
          <h3><?php the_field( 'title' ); ?></h3>
        </div>
        <div class="large-6 medium-7 small-10 small-centered large-centered columns browser">
          <img src="<?php the_field( 'screenshot' ); ?>" alt="Kelli Lynn Photography browser screenshot"> 
        </div>
        <div class="large-8 medium-10 small-12 large-centered medium-centered columns">
          <?php the_field( 'project_description' ); ?>
          <p>View more of this project on <a href="<?php the_field( 'dribbble_url' ); ?>">dribbble</a>.</p>
        </div>
      </div>
    </section>

<?php endwhile; else: ?>

    <p>There are no posts or pages to display.</p>

<?php endif; ?>

That looks good to me to be honest.

Unless I'm not fully understanding what you're saying.

Brett Smith
Brett Smith
4,261 Points

That works perfectly on a multiple page site. I guess I don't fully understand exactly what I'm doing to combine all of the pages. I've been using the following code to combine the pages:

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

When I do this it shows the home page post about 5 times and no other posts. Am I missing something?

Brett Smith
Brett Smith
4,261 Points

That works perfectly on a multiple page site. I guess I don't fully understand exactly what I'm doing to combine all of the pages. I've been using the following code to combine the pages:

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

When I do this it shows the home page post about 5 times and no other posts. Am I missing something?