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

Colin Stodd
Colin Stodd
6,257 Points

Static page template to build page via WYSIWYG editor in Wordpress

I am building out a blog for a friend that has very little HTML knowledge; And I was hoping to be able to build out some static pages having the header, footer, and CSS as a template where they could then builld out the pages with short codes and some of my other HTML (added via the WYSIWYG editor).

I'm hoping for something like this:

<?php
/*----------------------------------------
   Template name: Friends Page
----------------------------------------*/

 ?>

 <?php get_header(); ?>

/* Blank so that I can fill out the page with code via the WYSIWYG editor */

<?php get_footer(); ?>

2 Answers

Tim Knight
Tim Knight
28,888 Points

Hi Colin,

So if I'm understanding this correctly, this is still just a template page that has to pull the details from the post that you added using the WYSIWYG editor. Remember a "Page" is just a post-type in WordPress so because of that you still have to pull the details from a the post and deal with the WP_Loop. Your code would look something like this:

<?php
/*
  Template Name: Friends Page
*/

?>
<?php get_header(); ?>

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        <h1><?php the_title(); ?></h1>
        <?php the_content(); ?>
    <?php endwhile; endif; ?>

<?php get_footer(); ?>

This would output the page title within the H1 and all of the content from within the WYSIWYG editor below that. If you don't want to include the title you can just remove that h1 and the_title() call.

Colin Stodd
Colin Stodd
6,257 Points

Hey Tim thank you for responding. I dont want to pull in any posts. I want a static pages so that my friend can go in to each page and add content via the WYSIWYG editor (i have the blog built). Similar to how you would create a page via a CMS editor. You just go in and add tables, text, or whatever by editing the page via the WYSIWYG editor. I dont want her to have to touch the code, just add text and change images.

I think I may have found a work around via widgets, but I really wish I could go into the page select a template such as "default" (being header, footer, and my custom/bootstrap CSS) and fill out the page via the WYSIWYG page editor.

Tim Knight
Tim Knight
28,888 Points

Hi Colin,

That's exactly what this template is. Since WordPress started as a blogging tool it considers anything that was added into the site a "post". A "Page" that you would add in the Pages section of the WordPress admin is just a type of post (called a Post-Type). If you take this code and call it something like page-friends.php and within the page you select "Friends Page" from within that page on WP you'll see that anything you add in the WYSIWYG will be output on this page.

Colin Stodd
Colin Stodd
6,257 Points

Ahhhh, thanks for some clarification! I'm going to give it a shot as soon as I get out of work and I'll swing back to let you know how it goes. I really appreciate you taking the time to explain!

Colin Stodd
Colin Stodd
6,257 Points

Thank you, thank you, thank you!!!! Exactly what I was hoping for. I've been working for days to try and figure this out. MUCH APPRECIATED!