简体   繁体   中英

wordpress output the content of a static home page instead of all available posts

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...

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM