为什么我的页面内容在此WordPress页面中的帖子上方丢失?

时间:2019-04-04 23:10:11

标签: php wordpress

我创建了一个新的页面模板来显示帖子;但是,页面内容不会显示在页面上。

我已经尝试过更新页面中的php,但无法弄清楚。

...

<div class="container">
    <div class="row responsive">
        <div class="col-md-9 col-sm-12 col-xs-12 content main-container">
            <?php
                    $wp_query = new WP_Query( array(
                        'post_type'           => 'podcast',
                        'posts_per_page'      => 12,
                    ) );
                ?>
            <?php while ( have_posts() ) : the_post(); ?>
            <?php echo get_post_field('post_content', $post->ID); ?>
                <?php the_content();
                wp_link_pages(); ?>
                <div class="podcast">
                    <div class="podcast-image">
                    <a href="<?php echo get_post_meta($post->ID, 'podcast_website', true); ?>" target="_blank" rel="noopener noreferrer"><img title="<?php the_title(); ?>" src="<?php echo get_post_meta($post->ID, 'podcast_image', true); ?>" alt="<?php the_title(); ?>" /></a>
                        <div class="podcast-text">
                            <h4><?php the_title(); ?></h4>
                        <h6><a title="Listen" href="<?php echo get_post_meta($post->ID, 'podcast_listen', true); ?>" target="_blank" rel="noopener noreferrer">Listen</a></h6>
                        </div><!--podcast-text-->
                    </div><!--podcast-image-->
                </div><!--podcast-->
        <?php endwhile;  ?>
        </div>

...

1 个答案:

答案 0 :(得分:1)

您实际上应该包括在循环中创建的查询。

<?php

// The Query
$the_query = new WP_Query( $args );

// The Loop
if ( $the_query->have_posts() ) {
    echo '<ul>';
    while ( $the_query->have_posts() ) {
        $the_query->the_post();
        echo '<li>' . get_the_title() . '</li>';
    }
    echo '</ul>';
    /* Restore original Post Data */
    wp_reset_postdata();
} else {
    // no posts found
} ?>

在这里$the_query->have_posts()

是可以理解的

Class Reference/WP Query-Usage

关于您的代码:

<div class="container">
    <div class="row responsive">
        <div class="col-md-9 col-sm-12 col-xs-12 content main-container">
            <?php
                    $wp_query = new WP_Query( array(
                        'post_type'           => 'podcast',
                        'posts_per_page'      => 12,
                    ) );
                ?>
            <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
            <?php echo get_post_field('post_content', $post->ID); ?>
                <?php the_content();
                wp_link_pages(); ?>
                <div class="podcast">
                    <div class="podcast-image">
                    <a href="<?php echo get_post_meta($post->ID, 'podcast_website', true); ?>" target="_blank" rel="noopener noreferrer"><img title="<?php the_title(); ?>" src="<?php echo get_post_meta($post->ID, 'podcast_image', true); ?>" alt="<?php the_title(); ?>" /></a>
                        <div class="podcast-text">
                            <h4><?php the_title(); ?></h4>
                        <h6><a title="Listen" href="<?php echo get_post_meta($post->ID, 'podcast_listen', true); ?>" target="_blank" rel="noopener noreferrer">Listen</a></h6>
                        </div><!--podcast-text-->
                    </div><!--podcast-image-->
                </div><!--podcast-->
        <?php endwhile;  ?>
        </div>