WordPress Pages
Pages are for the static content of your site, like About us, Contact or Privacy Policy. Unlike posts, pages are not shown by date and they do not use categories or tags.
Posts vs Pages
| Point | Posts | Pages |
|---|---|---|
| Content type | Time based (news, blog) | Timeless (about, contact) |
| Order | Newest first | Menu or page order |
| Categories and tags | Yes | No |
| Comments | Usually on | Usually off |
| Parent and child | No | Yes (page hierarchy) |
| In RSS feed | Yes | No |
| Page templates | No | Yes |
How to add a page
- Go to Pages > Add Page.
- Write the title and content with the block editor.
- In the settings sidebar, choose a Template and a Parent if needed.
- Click Publish.
Parent and child pages
A page can have a parent. Then its URL has the parent slug in front of it, which is good to organize big sites. Let us make one from the command line and see the URL:
$ wp post create –post_type=page –post_title="Services" –post_status=publish –porcelain
5
$ wp post create –post_type=page –post_title="Web Design" –post_parent=5 –post_status=publish –porcelain
6
$ wp post list –post_type=page –fields=ID,post_title,post_parent,post_status
ID post_title post_parent post_status
6 Web Design 5 publish
5 Services 0 publish
2 Sample Page 0 publish
3 Privacy Policy 0 draft
$ wp eval 'echo get_permalink(6);'
http://example.com/services/web-design/
Set a static home page
Create two pages, Home and Blog, and then go to Settings > Reading. Choose A static page and select them. The same can be done with WP-CLI:
$ wp post create –post_type=page –post_title="Home" –post_status=publish –porcelain
7
$ wp post create –post_type=page –post_title="Blog" –post_status=publish –porcelain
8
$ wp option update show_on_front page
Success: Updated 'show_on_front' option.
$ wp option update page_on_front 7
Success: Updated 'page_on_front' option.
$ wp option update page_for_posts 8
Success: Updated 'page_for_posts' option.
$ curl -s http://example.com/ | grep -o "<title>[^<]*</title>"
<title>Demo Site</title>
| Exercises & Assignments |
|---|
| Add categories, a child category and a tag to a post |