dongshijiao2363 2018-10-22 10:56
浏览 75
已采纳

创建静态页面wordpress

I'm facing a big issue with the right way of implementing the static page in Wordpress. I've read almost for 5 days along now, and still can't figure out how it (should) work.

The problem i'm facing is as followed:

When I make use of the option "show latest posts" in customizer, I see the front page as it should be. I got the text of the homepage followed by the latest posts. The problem I'm facing here, is the homepage text is hard coded in my home.php. I want to be able to change that on the input field of the home in my wordpress editor.

So I understood i should make use of the index.php and create a page called "Home" and a page called "Blog". I set those pages as static page, and i'll be able to accomplish what I want. But i don't. I just can't get it done.

So I tried it with a complete new installation of WP in my local machine. Setup a brand new installation, created just 2 pages (home and blog). Go to Settings-> Reading -> Set static page: Homepage: Home Post page: Blog. Saved changes.

Got to the homepage and i just saw my homepage. No posts up there.

What am i missing here?

  • 写回答

1条回答 默认 最新

  • duanchun1909 2018-10-22 11:05
    关注

    You are using a page called "Home" which is empty. It's expected and is fine. What you really need is to create a custom template (https://developer.wordpress.org/themes/template-files-section/page-template-files/#creating-custom-page-templates-for-global-use), and create any custom layout you want

    Extended Answer

    Create a template called homepage.tpl.php for example. Put this code inside:

    <?php
    /**
     * Template Name: Custom Homepage
     */
    
    get_header(); ?>
    
    <div>
      <?php    
      if ( have_posts() ) :    
         while ( have_posts() ) : the_post();
           the_content();
         endwhile;
      endif;   
      ?>  
    </div>
    
    <div>
      <?php
      $wp_query = new WP_Query(array(
        'post_type' => 'post',
        'post_status' => 'publish'
      ));
      if ( $wp_query->have_posts() ) :
        while ( $wp_query->have_posts() ) : $wp_query->the_post();
          the_title();
          /* Post loop content goes here */    
        endwhile;
        wp_reset_postdata();
      endif;
      ?>
    </div>
    
    <?php get_footer(); ?>
    

    Go the admin panel -> pages -> click edit "home". At the right sidebar select the template called "Custom Homepage". That's it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?