创建静态页面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?
网友观点:
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
<?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.
1. 带 [亲测] 说明源码已经被站长亲测过!
2. 下载后的源码请在24小时内删除,仅供学习用途!
3. 分享目的仅供大家学习和交流,请不要用于商业用途!
4. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
5. 本站所有资源来源于站长上传和网络,如有侵权请邮件联系站长!
6. 没带 [亲测] 代表站长时间紧促,站长会保持每天更新 [亲测] 源码 !
7. 盗版ripro用户购买ripro美化无担保,若设置不成功/不生效我们不支持退款!
8. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
9. 如果你也有好源码或者教程,可以到审核区发布,分享有金币奖励和额外收入!
10.如果您购买了某个产品,而我们还没来得及更新,请联系站长或留言催更,谢谢理解 !
GG资源网 » 创建静态页面wordpress