Set a static front page and a posts page

Description: Create two pages, Home and News. Make Home the front page of the site and News the page which lists the blog posts. Check the setting.

Hint:

  • The options are show_on_front, page_on_front and page_for_posts.

Solution

Terminal output

$ wp post create –post_type=page –post_title="Home" –post_status=publish –porcelain
5
$ wp post create –post_type=page –post_title="News" –post_status=publish –porcelain
6
$ wp option update show_on_front page
Success: Updated 'show_on_front' option.
$ wp option update page_on_front 5
Success: Updated 'page_on_front' option.
$ wp option update page_for_posts 6
Success: Updated 'page_for_posts' option.
$ curl -s -o /dev/null -w "%{http_code}\n" http://example.com/news/
200
$ wp option get page_on_front
5

How it works

  • show_on_front is page when you use a static page. The two other options keep the page IDs.
  • The News page now shows the latest posts at /news/.

Read WordPress Pages.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.