在WordPress中的文章post的问题

我一直停留在开发WP主题中, 请帮助我。问题是当我在front-page.php中编写用于显示帖子的代码时, 它从页面而不是从帖子显示the_title()和the_content()。有代码:

   <?php if(have_posts()): ?>
   <?php while(have_posts()) : the_post(); ?>
   <h2 class="blog-post-title"><?php the_title( );  ?> </h2>
   <?php the_content(); ?>
   <?php endwhile; else: ?>
   <p><?php __('No post found') ?></p>
   <?php endif; ?>

仅当我去发布位置时, 它才会显示我的发布本地主机/ 2017/10/16 / first-post /。

有图片如何正确显示, 但在另一个位置。

http://prntscr.com/gy922y


#1


由于你要显示在自定义页面中, 因此需要声明并将post_type指定为post

这是一个工作示例:

        <?php
    $args = array(
        'post_type' => 'post'
    );

    $post_query = new WP_Query($args);
if($post_query->have_posts() ) {
  while($post_query->have_posts() ) {
    $post_query->the_post();
    ?>
<h2 class="blog-post-title"><?php the_title( );  ?> </h2>
      <?php the_content(); ?>
    <?php
  }
}
?>

来源:

https://www.srcmini02.com/65704.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_37230.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?