dongsheng66783619 2016-01-25 20:52
浏览 34
已采纳

wordpress输出静态主页的内容而不是所有可用的帖子

I'm currently writing my first wordpress design and have some problems with the start page.

I want a static page to be the homepage. For this i made some changes to the page.php file to restructure it for the "home" page.

However when the specific page is set as start page the function

the_post()

Seems to output different results than when it's not the home page.

Used code:

while ( have_posts() ) : the_post(); 
    get_template_part( 'template-parts/content', 'page' ); 
endwhile;

This part of the code loops through my poosts instead of outputting the content of my current static page - which I actually want. It somehow works when the page is not the home / start page...

  • 写回答

1条回答 默认 最新

  • douba2011 2016-01-25 21:23
    关注

    The easiest would be to roll back to the original page.php, and copy the content of it into a new file named front-page.php. If present this file will always be used to display the front page. Then it's just a matter of doing all the needed modifications to this file.

    As a side note; your code is working on all other pages because they are static by default.

    There are also several other ways to go about this. Read more here: https://codex.wordpress.org/Creating_a_Static_Front_Page

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

报告相同问题?

悬赏问题

  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏