为什么我的Wordpress Post Loop无法正常工作?

时间:2017-07-29 07:40:03

标签: php html wordpress css3 loops

好的,我正在尝试运行wordpress post loop以使用func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { guard let panRecognizer = otherGestureRecognizer as? UIPanGestureRecognizer else { return false } let velocity = panRecognizer.velocity(in: panRecognizer.view) if (abs(velocity.x) > abs(velocity.y)) { return true } return false } the_title()打印帖子标题和内容。但它没有打印出页面上的帖子?

有什么想法吗?

的index.php

the_content()

编辑好的,我只收到打印出来的内容而不是帖子标题,这是一张图片:http://imgur.com/a/DiBqG

编辑2 在wordpress管理员帖子中应该如下所示:http://imgur.com/a/1DQAp

2 个答案:

答案 0 :(得分:0)

您没有定义查询并以错误的方式使用Wordpress内置功能。这是更正。

<?php
// The Query
$the_query = new WP_Query(  );
// 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
}

答案 1 :(得分:0)

为fetch post data添加以下代码

 <?php
    $post_args=array(
        'type'                     => 'post',
        'post_status'              => 'publish',
        'posts_per_page'           => -1,
        'orderby'                  => 'date',
        'order'                    => 'ASC',

    );

    $post_my_query = null;
    $post_my_query = new WP_Query($post_args);

    if( $post_my_query->have_posts() ) 
    {
        while ($post_my_query->have_posts()) : $post_my_query->the_post(); 
        ?>
        <h2><?php echo get_the_title( $post_my_query->ID );?></h2>
        <?php
             echo get_the_content( $post_my_query->ID );
          endwhile;
    }
    wp_reset_query($post_my_query);
?>