简体   繁体   中英

Loop in WordPress Page not working

Here is my page template:

It's not pulling the content in. Not sure what I'm missing?

<?php get_header(); ?>
    <section id="services">
        <div class="container">
            <div class="row divide">
            <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
            <h2><?php the_title(); ?></h2>
            <?php the_content(); ?>
            <?php endwhile; endif; ?>
            </div>
        </div>
    </section>
<?php get_footer(); ?>

This code is for display post list in template. Please try it.

get_header();
?>
<section id="services">
    <div class="container">
        <div class="row divide">
            <?php
            $args = array('post_type' => 'post');
            $postlist = new WP_Query($args);

            if ($postlist->have_posts()) {
                while ($postlist->have_posts()) {
                    $postlist->the_post();
                    the_title();
                    the_content();
                    // list posts here
                }

                // post pagination
            } else {
                // no posts content
            }
            ?>
        </div>
    </div>
</section>
<?php get_footer();

Try

<?php get_header(); ?>
        <section id="services">
            <div class="container">
                <div class="row divide">

      <?php      if ( have_posts() ) {
            while ( have_posts() ) {
            the_post(); 
            //
            // Post Content here 
            //
            } // end while
            } // end if
       ?>
                </div>
            </div>
        </section>
    <?php get_footer(); ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM