search
HomeCMS TutorialWordPressUnderstanding WordPress Pages and the Pages API

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
)); ?>

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'
)); ?>

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'
)); ?>

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'
)); ?>

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
)); ?>

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
)); ?>

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'
)); ?>

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'
)); ?>

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
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
How to add a comment box to WordPressHow to add a comment box to WordPressApr 20, 2025 pm 12:15 PM

Enable comments on your WordPress website to provide visitors with a platform to participate in discussions and share feedback. To do this, follow these steps: Enable Comments: In the dashboard, navigate to Settings > Discussions, and select the Allow Comments check box. Create a comment form: In the editor, click Add Block and search for the Comments block to add it to the content. Custom Comment Form: Customize comment blocks by setting titles, labels, placeholders, and button text. Save changes: Click Update to save the comment box and add it to the page or article.

How to copy sub-sites from wordpressHow to copy sub-sites from wordpressApr 20, 2025 pm 12:12 PM

How to copy WordPress subsites? Steps: Create a sub-site in the main site. Cloning the sub-site in the main site. Import the clone into the target location. Update the domain name (optional). Separate plugins and themes.

How to write a header of a wordpressHow to write a header of a wordpressApr 20, 2025 pm 12:09 PM

The steps to create a custom header in WordPress are as follows: Edit the theme file "header.php". Add your website name and description. Create a navigation menu. Add a search bar. Save changes and view your custom header.

How to display wordpress commentsHow to display wordpress commentsApr 20, 2025 pm 12:06 PM

Enable comments in WordPress website: 1. Log in to the admin panel, go to "Settings" - "Discussions", and check "Allow comments"; 2. Select a location to display comments; 3. Customize comments; 4. Manage comments, approve, reject or delete; 5. Use <?php comments_template(); ?> tags to display comments; 6. Enable nested comments; 7. Adjust comment shape; 8. Use plugins and verification codes to prevent spam comments; 9. Encourage users to use Gravatar avatar; 10. Create comments to refer to

How to upload source code for wordpressHow to upload source code for wordpressApr 20, 2025 pm 12:03 PM

You can install the FTP plug-in through WordPress, configure the FTP connection, and then upload the source code using the file manager. The steps include: installing the FTP plug-in, configuring the connection, browsing the upload location, uploading files, and checking that the upload is successful.

How to copy wordpress codeHow to copy wordpress codeApr 20, 2025 pm 12:00 PM

How to copy WordPress code? Copy from the admin interface: Log in to the WordPress website, navigate to the destination, select the code and press Ctrl C (Windows)/Command C (Mac) to copy the code. Copy from a file: Connect to the server using SSH or FTP, navigate to the theme or plug-in file, select the code and press Ctrl C (Windows)/Command C (Mac) to copy the code.

What to do if there is an error in wordpressWhat to do if there is an error in wordpressApr 20, 2025 am 11:57 AM

WordPress Error Resolution Guide: 500 Internal Server Error: Disable the plug-in or check the server error log. 404 Page not found: Check permalink and make sure the page link is correct. White Screen of Death: Increase the server PHP memory limit. Database connection error: Check the database server status and WordPress configuration. Other tips: enable debug mode, check error logs, and seek support. Prevent errors: regularly update WordPress, install only necessary plugins, regularly back up your website, and optimize website performance.

How to close comments with wordpressHow to close comments with wordpressApr 20, 2025 am 11:54 AM

How to turn off a comment in WordPress? Specific article or page: Uncheck Allow comments under Discussion in the editor. Whole website: Uncheck "Allow comments" in "Settings" -> "Discussion". Using plug-ins: Install plug-ins such as Disable Comments to disable comments. Edit the topic file: Remove the comment form by editing the comments.php file. Custom code: Use the add_filter() function to disable comments.

See all articles

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment