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

    Thanks!

Viewing 11 replies - 1 through 11 (of 11 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Have you tried using get_the_content() within the loop?
    http://codex.wordpress.org/Function_Reference/get_the_content

    Thread Starter gutterboy333

    (@gutterboy333)

    I thought that was just for the blog part of the site (posts, not pages)?

    Also trying to get a better understanding of the above method and how it’s used so I can use it properly when needed. πŸ™‚

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    How about the function the_content()?
    http://codex.wordpress.org/Function_Reference/the_content

    Try using these functions within the loop,
    E.g

    if (have_posts()) :
       while (have_posts()) :
          the_post();
          the_content();
       endwhile;
    endif;

    Thread Starter gutterboy333

    (@gutterboy333)

    Nope, doesn’t work.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    What doesn’t work exactly?

    Thread Starter gutterboy333

    (@gutterboy333)

    It doesn’t output anything when I use that.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    The static page you’ve made, have you assigned the correct template?

    Thread Starter gutterboy333

    (@gutterboy333)

    It’s using the default template. The page is coming up fine when I go to the index page, but the content (from the admin->pages editor) just isn’t showing up.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Have you looked at Twenty Eleven or Twenty Ten, the default WordPress themes, to see how those themes manage it?

    Thread Starter gutterboy333

    (@gutterboy333)

    Yeah, it’s similar, it has this..

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

    So I’m guessing that uses content.php. I go and look at this file and it contains a whole bunch of code. But I don’t need any more code/html – what do I put in there? Do I have to separate my code or something?

    So confusing!!

    Thread Starter gutterboy333

    (@gutterboy333)

    Ok, if I call it the same 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!?

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘Confused on loading page content’ is closed to new replies.