Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm building my first full site into WP and I am rather confused on the process involved to load the content you enter via the WP Pages editor into the actual page.

For example, I am having a static home page and I have this in index.php of my theme file.

// Output header
get_header('home');

// Start Code that wraps the content

/***** Content of the page ******/

// End Code that wraps the content

get_sidebar();

get_footer();

Now the "Content of the page" should be the code/content that the user has control over via the WP Admin Pages menu.

How do I get this into the page? I have read you need to do something like this..

if (have_posts()) {

    /* Start the Loop */

    while (have_posts()) {
        the_post();
        get_template_part('content');
    }

}

But I'm confused as this uses another content page yet again (content.php). Why do I need to create another content page when all I need is the code/data from the pages content area? I don't need to add any more coding myself.

I played around with it a bit and if I call it this way and make a content.php file and just put <?php the_content(); ?> inside of it, the content shows.

Still confused on the purpose of doing it this way.

I'm assuming so that you can use the index file for many things and then put specific code differences inside the content file!?

To help you understand my question even more, I have included the exact code from my index.php file below and I'm wondering how I would split this up between index.php and content.php?

<?php

// Output header
get_header('home');

?>

    <div id="main_holder">
        <div class="banner">
            <div id="slider">
                <div class="slide slide1">
                    <div class="title">
                        <p>We Navigate the</p>
                        <p>Maze for You</p>
                    </div>
                    <div class="text">
                        We provide a start-to-finish service in an area<br />
                        that can often be complex and confusing.
                    </div>
                    <div class="button button_big">
                        <a href="">Read more about<br /><span>registering a trademark</span></a>
                    </div>
                </div>
                <!-- Slide 1 Ends -->
            </div>
            <!-- Slider Ends -->
        </div>
        <!-- Banner Ends -->
        <div class="content">
            <div class="main">
                <div class="search_button">
                    <div class="left">
                        <h2><a href="<?php echo get_permalink(10); ?>">Free Trademark Search</a></h2>
                    </div>
                    <div class="right">
                        <a href="<?php echo get_permalink(10); ?>">Get Started Now!</a>
                    </div>
                </div>
                <!-- Search Button Ends -->

<?php

                if (have_posts()) {

                    /* Start the Loop */

                    while (have_posts()) {
                        the_post();
                        get_template_part( 'content', get_post_format() );
                    }

                } 

?>

            </div>
            <!-- Main Ends -->
             <?php get_sidebar(); ?> 
            <div class="contentClear"></div>
        </div>
        <!-- Content Ends -->
    </div>
    <!-- Main Holder Ends -->
    <div class="bottom"></div>

<?php

// Ouput footer
get_footer();

?>

Thanks very much!

share|improve this question
    
You do not have to use get_template_part if you do not want to. I believe the purpose is so that you can reuse content.php across multiple templates. –  Joseph Aug 25 '12 at 20:09
    
@Joseph Thanks. I used the_content() instead just inside index.php and it worked; which is strange as I'm sure I tried it before and it didn't work haha..... thanks for the response. :) –  Brett Aug 26 '12 at 7:34
add comment

1 Answer 1

I don't think there is need to mess up with index.php or any other file for creating a static home page. You can create a static home page by following these steps: first publish the page from wp-admin, then go to settings >> reading >> front page displays >> a static page >> select your page from the list. That said, if you have some special requirements for your home page and need to write custom code then you should create a new file as front-page.php in your theme. The content of this file could be like:

<?php get_header(); ?>

<!-- all your custom code can go here -->

<?php get_sidebar();
<?php get_footer(); ?>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.