Table of Contents
Add, edit and delete pages
Organization Page
Show page list
Filter the output
Custom output
Retrieve page
What is the difference between a WordPress page and an article?
How to use the WordPress REST API to retrieve page content?
How to create a new page using the WordPress REST API?
How to update pages using WordPress REST API?
How to use the WordPress REST API to delete a page?
How to use the WordPress REST API to retrieve a list of all pages?
How to use the WordPress REST API to retrieve a list of all published pages?
How to use the WordPress REST API to retrieve a list of all draft pages?
How to use the WordPress REST API to retrieve a list of all private pages?
How to use the WordPress REST API to retrieve a list of all pending pages?
Home CMS Tutorial WordPress Understanding WordPress Pages and the Pages API

Understanding WordPress Pages and the Pages API

Feb 09, 2025 am 09:25 AM

WordPress Pages and Articles: Static Content Management and API Applications

Understanding WordPress Pages and the Pages API

WordPress pages and articles differ, and they are suitable for different types of website content. This article will explain the purpose of the page and the difference from the article, and explain how to manage pages on a WordPress website. Finally, we will discuss the related functions of the WordPress page API.

Key points:

  • WordPress pages are used to display static, permanent information on a website, such as the Contact Us or About Us page, which has nothing to do with time, unlike WordPress articles.
  • Users with editing or administrator rights can manage WordPress pages, including adding, editing, and deleting pages, and using the Page Properties box to organize page hierarchies.
  • The WordPress Page API allows customization and filtering of displayed pages, including displaying a page list, limiting the number of pages displayed, customizing output, and searching pages.
  • The
  • get_pages() function can be used to retrieve an array of page lists, while the get_post() function is used to retrieve a single page. These functions allow further customization and manipulation of the page before it is displayed.

What is a WordPress page?

The WordPress page is a content page on a website, such as the Contact Us or About Us page. We often see links to these pages in the main navigation, sidebar, or footer of the website.

The main difference between a page and an article is the relevance of time: the article is usually related to time, while the content of the page is usually permanent.

When publishing a news or tutorial, the time context is very important. New features won't always be new and may not exist in some cases in a few years. This is why it is better to use articles when writing such content.

On the other hand, if you want to describe the purpose of the website, or provide a contact form, you should use the page. This is a static content type that does not change over time.

How to manage WordPress pages?

Add, edit and delete pages

If you have edit or administrator rights, you can manage pages in WordPress. To do this, go to Pages in the WordPress dashboard and you will see a list of all pages, or you can create a new page with the Add New Page button.

Understanding WordPress Pages and the Pages API This list is similar to the "Article" list and is used the same way. You can click on the page's title to edit, and when you hover over the page's title, there are some other useful shortcut links that appear.

When you click to edit or add a page or article, you can specify the title and content, and if your theme supports it, you can also add featured images. The Publish button allows you to publish a page. Otherwise, if you are not ready to go live, you can save it as a draft.

Organization Page

To organize articles, categories and tags can be used. However, there is no similar way to organize the page. Pages can still be organized by hierarchy. In fact, you can specify a page as a subpage of another page. It's like creating a subcategory for your category.

To create a child page, go to the Page Properties box, where you will find a drop-down list called Parent Page. In this list, select the page you want to be the parent page that is currently created or edited. Note that you can also create sub-subpages, sub-subpages, etc. to create your own hierarchy.

By default, pages are sorted alphabetically (by title). You can customize this order through the Order field in the Page Properties section. The pages will then be sorted by the number you indicate in this field. For example, if you have three pages titled "Page 1", "Page 2", and "Page 3", they will be displayed in this order by default. If you want "Page 3" to appear first, indicate its order as 0 and the order of other pages as larger numbers (such as 1 and 2).

WordPress Page API

Show page list

To display a list of pages, WordPress provides the wp_list_pages() function. By default, it displays HTML code containing an unordered list of all published pages encapsulated in a li tag with an h2 title indicating "page". It also accepts a parameter: an associative array, which lists some options for custom output.

Filter the output

There are some options available to limit the number of pages displayed. The first option we will see is child_of. It allows us to display pages with a given page as parent page. The following example shows a subpage with page ID 2:

<?php wp_list_pages(array(
    'child_of' => 2
)); ?>
Copy after login
Copy after login

The authors option is very useful when we want to display a page written by one or more authors. This option accepts strings as values: a comma-separated list of author IDs. Using the following parameters, the function will display a page written by two authors:

<?php wp_list_pages(array(
    'authors' => '2,7'
)); ?>
Copy after login
Copy after login

To display only certain pages, use the include option. You can provide a comma-separated list of page IDs for this option and you will get a list of these pages:

<?php wp_list_pages(array(
    'include' => '7,53,8'
)); ?>
Copy after login
Copy after login

In contrast, if you want to hide certain pages, you can use the exclude option, which accepts the same type of value:

<?php wp_list_pages(array(
    'exclude' => '2,4'
)); ?>
Copy after login

You can also choose to filter by depth. For example, if you want to view only the top page, you can use the depth option.

By default, it is set to 0 and all pages are displayed. Set it to any positive number and you will only get pages of this depth. For example, indicating 1 will only display the top-level page. The following example shows these same pages and their direct subpages:

<?php wp_list_pages(array(
    'depth' => 2
)); ?>
Copy after login

By default, wp_list_pages() only published pages are displayed. However, you can use the post_status option to display other pages.

Use this option to display the status you want to see, separated by commas. The following example shows published pages and drafts:

<?php wp_list_pages(array(
    'child_of' => 2
)); ?>
Copy after login
Copy after login

In addition to filtering the list of retrieved pages, you can also use the number option to limit the number of retrieved pages. If you use a positive number, you will only retrieve a limited number of pages.

Custom output

You can customize the title using the title_li option, which accepts strings as values. By default, it is set to Page, and you can then select any text to display. You can also set it to an empty string.

This way, wp_list_pages() will not encapsulate your page into the li tag, and you will get the li tag of the page directly.

Retrieve page

The

wp_list_pages() function allows you to get a list of HTML for the page. This function is not the best option if you want to create your own HTML, or if you need to apply certain actions to the page before displaying it. Instead, you prefer to use get_pages() to retrieve arrays listing different pages.

This function also accepts an array as an argument, listing the required options. The good news is that you already know some of these options, as we have already introduced them in the description of the wp_list_pages() function: child_of, authors, include, exclude, post_status, number, sort_column, sort_order, 🎜> and

.

get_pages() By default, the hierarchy of the page is displayed in hierarchical: the child page appears after its parent page. You can disable this behavior by setting the

option to false. This way, all pages will be treated equally and the hierarchy will be completely ignored.

Retrieve a single page

The get_pages()get_post() function returns an array of required pages, each represented by a WP_Post object. We will now understand what is included in this object by retrieving only one page. To retrieve a page, use the

function. Provide this function with the ID of the page and you will get the object representing this page:
<?php wp_list_pages(array(
    'authors' => '2,7'
)); ?>
Copy after login
Copy after login

This object provides multiple pieces of information, each piece of information being a property. For example, you can use the ID attribute to get the ID of the page:
<?php wp_list_pages(array(
    'include' => '7,53,8'
)); ?>
Copy after login
Copy after login

post_contentpost_title allows you to retrieve the content of a page, and its title is in the post_name property. The

attribute contains the slug of the page (the part of its URL that represents the page title).

The page author's ID is given by the post_author attribute. You can also use post_date to retrieve its creation date and use post_modified to retrieve its last modified date. The post_status property allows you to understand the status of the page (such as published or drafted).

The ID of the parent page can be obtained using the post_parent property, which will give you the order indicated when creating the page. menu_order

Conclusion

If you want to add some static, permanent information to your website, then the WordPress page is the solution.

Functions of the WordPress page API are very useful if you are developing a theme. For example, you can list certain pages in the footer, or create widgets to do this so that your users can list pages wherever they want.

Frequently Asked Questions for WordPress Pages and Pages APIs

What is the difference between a WordPress page and an article?

WordPress pages and articles are two different types of content. Pages are static and not affected by time, while articles are time-related and used for dynamic content. Pages are often used for content whose content does not change frequently, such as the About Us or Contact Us page. Articles, on the other hand, are used for blogs, news updates, and other content that is regularly updated.

How to use the WordPress REST API to retrieve page content?

The WordPress REST API provides an endpoint for WordPress data type that allows interaction with your WordPress website over the HTTP protocol. To retrieve page content, you can send a GET request to the /wp/v2/pages endpoint. This returns a JSON object containing all pages on your website. You can also retrieve specific pages by attaching the page ID to the endpoint, such as /wp/v2/pages/<id></id>.

How to create a new page using the WordPress REST API?

To create a new page using the WordPress REST API, you can send a POST request to the /wp/v2/pages endpoint. The request should contain a JSON object containing the title, content, and status of the page. The status can be "Publish", "Pending", "Draft", or "Private". The API returns a JSON object containing the details of the newly created page.

How to update pages using WordPress REST API?

To update a page using the WordPress REST API, you can send a POST request to the /wp/v2/pages/<id></id> endpoint, where <id></id> is the ID of the page you want to update. The request should contain a JSON object containing the updated title, content, or status. The API returns a JSON object with details about the update page.

How to use the WordPress REST API to delete a page?

To delete a page using the WordPress REST API, you can send a DELETE request to the /wp/v2/pages/<id></id> endpoint, where <id></id> is the ID of the page you want to delete. The API returns a JSON object with details about the deleted page.

How to use the WordPress REST API to retrieve a list of all pages?

To use the WordPress REST API to retrieve a list of all pages, you can send a GET request to the /wp/v2/pages endpoint. This returns a JSON object containing a list of all pages on your website.

How to use the WordPress REST API to retrieve a list of all published pages?

To use the WordPress REST API to retrieve a list of all published pages, you can send a GET request to the /wp/v2/pages endpoint and set the "status" parameter to "publish". This returns a JSON object containing a list of all published pages on your website.

How to use the WordPress REST API to retrieve a list of all draft pages?

To use the WordPress REST API to retrieve a list of all draft pages, you can send a GET request to the /wp/v2/pages endpoint and set the "status" parameter to "draft". This returns a JSON object containing a list of all draft pages on your website.

How to use the WordPress REST API to retrieve a list of all private pages?

To use the WordPress REST API to retrieve a list of all private pages, you can send a GET request to the /wp/v2/pages endpoint and set the "status" parameter to "private". This returns a JSON object containing a list of all private pages on your website.

How to use the WordPress REST API to retrieve a list of all pending pages?

To use the WordPress REST API to retrieve a list of all pending pages, you can send a GET request to the /wp/v2/pages endpoint and set the "status" parameter to "pending". This returns a JSON object containing a list of all pending pages on your website.

The above is the detailed content of Understanding WordPress Pages and the Pages API. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Is WordPress easy for beginners? Is WordPress easy for beginners? Apr 03, 2025 am 12:02 AM

WordPress is easy for beginners to get started. 1. After logging into the background, the user interface is intuitive and the simple dashboard provides all the necessary function links. 2. Basic operations include creating and editing content. The WYSIWYG editor simplifies content creation. 3. Beginners can expand website functions through plug-ins and themes, and the learning curve exists but can be mastered through practice.

What is the WordPress good for? What is the WordPress good for? Apr 07, 2025 am 12:06 AM

WordPressisgoodforvirtuallyanywebprojectduetoitsversatilityasaCMS.Itexcelsin:1)user-friendliness,allowingeasywebsitesetup;2)flexibilityandcustomizationwithnumerousthemesandplugins;3)SEOoptimization;and4)strongcommunitysupport,thoughusersmustmanageper

Can I learn WordPress in 3 days? Can I learn WordPress in 3 days? Apr 09, 2025 am 12:16 AM

Can learn WordPress within three days. 1. Master basic knowledge, such as themes, plug-ins, etc. 2. Understand the core functions, including installation and working principles. 3. Learn basic and advanced usage through examples. 4. Understand debugging techniques and performance optimization suggestions.

How much does WordPress cost? How much does WordPress cost? Apr 05, 2025 am 12:13 AM

WordPress itself is free, but it costs extra to use: 1. WordPress.com offers a package ranging from free to paid, with prices ranging from a few dollars per month to dozens of dollars; 2. WordPress.org requires purchasing a domain name (10-20 US dollars per year) and hosting services (5-50 US dollars per month); 3. Most plug-ins and themes are free, and the paid price ranges from tens to hundreds of dollars; by choosing the right hosting service, using plug-ins and themes reasonably, and regularly maintaining and optimizing, the cost of WordPress can be effectively controlled and optimized.

Should I use Wix or WordPress? Should I use Wix or WordPress? Apr 06, 2025 am 12:11 AM

Wix is ​​suitable for users who have no programming experience, and WordPress is suitable for users who want more control and expansion capabilities. 1) Wix provides drag-and-drop editors and rich templates, making it easy to quickly build a website. 2) As an open source CMS, WordPress has a huge community and plug-in ecosystem, supporting in-depth customization and expansion.

Is WordPress a CMS? Is WordPress a CMS? Apr 08, 2025 am 12:02 AM

WordPress is a Content Management System (CMS). It provides content management, user management, themes and plug-in capabilities to support the creation and management of website content. Its working principle includes database management, template systems and plug-in architecture, suitable for a variety of needs from blogs to corporate websites.

Is WordPress still free? Is WordPress still free? Apr 04, 2025 am 12:06 AM

The core version of WordPress is free, but other fees may be incurred during use. 1. Domain names and hosting services require payment. 2. Advanced themes and plug-ins may be charged. 3. Professional services and advanced features may be charged.

Why would anyone use WordPress? Why would anyone use WordPress? Apr 02, 2025 pm 02:57 PM

People choose to use WordPress because of its power and flexibility. 1) WordPress is an open source CMS with strong ease of use and scalability, suitable for various website needs. 2) It has rich themes and plugins, a huge ecosystem and strong community support. 3) The working principle of WordPress is based on themes, plug-ins and core functions, and uses PHP and MySQL to process data, and supports performance optimization.

See all articles