Contacts

Controlling the display of pages in WordPress using a plugin. WordPress Pages: Everything About WordPress Pages Page List Plugin for Wordpress

Lists persistent pages as links.

Typically used in header.php (site header) or sidebar.php (sidebar) files to create menus.

See also the very similar wp_page_menu () function;

An alternative for creating menus is the wp_nav_menu () function, added since version 3.0. Manual.

✈ 1 time = 0.014449s = brake| 50,000 times = 213.16s = brake| PHP 7.1.2, WP 4.7.3

Function hooks

Usage

Usage pattern

$ args = array ("depth" => 0, "show_date" => "", "date_format" => get_option ("date_format"), "child_of" => 0, "exclude" => "", "exclude_tree" => "", "include" => "", "title_li" => __ ("Pages"), "echo" => 1, "authors" => "", "sort_column" => "menu_order, post_title" , "sort_order" => "ASC", "link_before" => "", "link_after" => "", "meta_key" => "", "meta_value" => "", "number" => "", "offset" => "", "walker" => "", "post_type" => "page", // from the get_pages () function); wp_list_pages ($ args);

Apart from the parameters below, the function can take all the same parameters as get_pages (), because it works on its basis.

Depth (number)

This parameter controls the nesting level of child pages that will be included in the list. The default is 0 (show all child pages, including double or more nesting).

  • 0 (default) List all nested page levels and display them in a tree view.
  • -1 Include all levels of nested pages in the list, but do not show nesting (the tree-like display of the list is disabled, the list will be shown as a general one).
  • 1 Show only the first subpages, i.e. child pages of the first level.
  • 2, 3, etc. List child pages 2, 3, etc. level ...

Default: 0

Show_date (line)

Shows the date the page was created or modified, next to the link. By default, dates are disabled.

  • "" - do not show dates (default).
  • modified - show the modified date.
  • created - show the date when the page was created.

Default: null

Date_format (line) Controls how the date will be displayed if the show_date parameter is enabled, for example, d / m / Y will output: 10/11/2011
Default: date settings in WordPress child_of (number) Show only child pages of the single page specified in this parameter. You need to specify the ID of the page, the subpages of which we want to display. By default 0 - show all pages.
Default: 0 exclude (line) In this parameter, we specify the IDs of those pages separated by commas that we do not want to be included in the list, for example: exclude = 3,7,31.
Default: "" exclude_tree (line) Specify the ID of the parent of the pages that you want to exclude from the list, separated by commas. All nested (child pages) of the specified IDs will also be excluded. Those. this parameter excludes the entire page tree from the list.
Added in version 2.7.
Default: "" include (string / array)

Show only the specified pages in the list. The ID can be specified with a comma or a space as a string: include = 45 63 78 94 128 140.

This parameter overrides the parameters related to the formation of the list, since it creates a list only from those pages that are specified. Parameters are canceled: exclude, child_of, depth, meta_key, meta_value, authors.
Default: ""

Title_li (line) List header. Default: __ ("Pages") __ ("") needed for localization. If you set this parameter to zero (""), then the list header will not be shown, and HTML tags that frame the list () will also be removed.
Default: __ ("Pages") echo (logical) Display the result on the screen (true) or return it for processing (false).
Default: true authors (line) Show pages owned only by the authors specified in this parameter. You need to specify the author's ID, separated by commas.
Default: "" sort_column (line)

Sort the list by the specified fields. By default, the list is sorted by title (post_title), in alphabetical order. You can specify several parameters separated by commas, according to which the list will be sorted later.

  • post_title - sort by title (alphabetically);
  • menu_order - sort by order, which is indicated on the admin panel on the "permanent page" edit page;
  • post_date - sort by the creation date of the "permanent page";
  • post_modified - sort by the date the page was modified;
  • ID - sort by record identifier in the Database (by ID);
  • post_author - sort by author ID;
  • post_name - sort alphabetically by post alias (usually transliterated title).

Default: "menu_order, post_title"

Sort_order (line) Sorting direction: "ASC" - in order, "DESC" - in reverse order.
Default: "ASC" link_before (line) Specify here the text or HTML code that will be inserted before the link text (inside the tag ). Added in version 2.7.
Default: "" link_after (line) Specify here the text or HTML code that will be inserted after the link text (inside the tag
). Added in version 2.7.
Default: "" meta_key (line) Will display pages that have only the specified custom fields (works only in conjunction with the meta_value parameter).
Default: "" meta_value (line) Will display pages that have only the specified custom field values ​​(the custom field key must be specified in the meta_key parameter).
Default: "" number (number) Limiting the number of links in the list (SQL LIMIT). In some cases it may not work.
Default: no offset (number) Top padding of the list. For example, if you specify 5, then the first 5 links that should have been shown will not be shown in the list.
Added in version 2.8.
Default: no item_spacing (line) Whether or not to leave line breaks in the HTML code of the menu. Can be: preserve or discard. C WP 4.7.
Default: "preserve" walker (line) php The class that handles the building of the list.
Default: ""

Examples of

# 1 Remove or change the title of the list

# 1.1 Remove the title of the list by canceling the title_li parameter.

Keep in mind that ul tags will also be removed and must be specified separately:

# 1.2. Change the title

Change the title to "Poets", wrap it in an HTML tag

and display only permanent pages with IDs 9, 5 and 23 in the list:

    ". __ (" Poetry ")."

"); ?>

# 2 Sorting the page list

# 2.1 Let's sort the list in accordance with the ordinal numbers indicated on the "permanent pages" edit page:

# 2.2 Using this code, we will remove the "Pages" title from the list:

# 2.3 Now we will display a list sorted by the creation date of the "permanent page" and show the date next to each link:

# 3 Exclude and Include Pages

# 3.1 Using the parameter exclude exclude pages with ID 17.38:

# 3.2 Using the parameter include, let's create a list of only pages in ID 35, 7, 26 and 13:

    ". __ (" Pages ").""); ?>

# 4 Display child pages

# 4.1 Display the list of child pages

Using the following example, you can display in the sidebar (or elsewhere) a list of child pages (subpages) of the permanent page you are currently visiting. To do this, we will use the parameter child_of and checking if there are any child pages for the current one (let's try to get child pages into the $ children variable, if possible, display the list):

ID. "& Echo = 0"); if ($ children) (?>

# 4.2. Static list of child pages

post_parent) $ children = wp_list_pages ("title_li = & child_of =". $ post-> post_parent. "& echo = 0"); else $ children = wp_list_pages ("title_li = & child_of =". $ post-> ID. "& echo = 0"); if ($ children) (?>

This example can be used in the sidebar (sidebar), but you need to understand that it first checks for the presence of a parent page for the current one, if it exists, then a list of single-level pages is displayed, if there is no parent page, then a list of child pages is displayed. Thus, we will have a closed list for the top-level pages on all pages.

# 4.3. An alternative to the previous code. This example can also be used in the sidebar, it will output:

    when you are on the main page, all the top-level "persistent pages" will be shown;

    when you are on a top-level "permanent page" that has no child pages, the same top-level "permanent pages" will be shown;

    when you are on a top-level "permanent page" that has child pages, those child pages and their child pages will be shown;

  • when you are on a child page of a top-level "permanent page" (on a second-level page), the child pages of the top-level "permanent page" (ie, child pages of the parent) will be shown.
Top-level pages"); if (is_page ()) ($ page = $ post-> ID; if ($ post-> post_parent) ($ page = $ post-> post_parent;) $ children = wp_list_pages (" echo = 0 & child_of = ". $ page. "& title_li ="); if ($ children) ($ output = wp_list_pages ("echo = 0 & child_of =". $ page. "& title_li =

Child pages

");)) echo $ output;?>

# 4.4 List of pages only if there is one

A list of child pages that will only be shown if the "permanent page" has child pages. Child pages will be shown both on the parent "permanent page" and on the child pages themselves. The difference from the previous example is the presence of the name of the parent "permanent page" in the list header:

post_parent) ($ children = wp_list_pages ("title_li = & child_of =". $ post-> post_parent. "& echo = 0"); $ titlenamer = get_the_title ($ post-> post_parent);) else ($ children = wp_list_pages ("title_li = & child_of = ". $ post-> ID." & echo = 0 "); $ titlenamer = get_the_title ($ post-> ID);) if ($ children) (?>

# 4.5 How to get all child pages, on "permanent pages" of any nesting level:

post_parent) (// get child pages for the top-level "permanent page" $ children = wp_list_pages ("title_li = & child_of =". $ post-> ID. "& echo = 0");) else (// get child pages, if we are on a first level child page. // $ children = wp_list_pages ("title_li = & child_of =". $ post-> post_parent. "& echo = 0"); if ($ post-> ancestors) (// now get the ID the very first page (oldest) // wp collects the ID in reverse order, so the "first" page will be the last one $ ancestors = end ($ post-> ancestors); $ children = wp_list_pages ("title_li = & child_of =". $ ancestors. " & echo = 0 "); // that's it, now we will always have a list of all child pages, // what nesting level we are at.)) if ($ children) (?>

# 4.6 Tree of child pages of the specified "permanent page"

Since there is no way to specify wp_list_pages display a tree (all nesting levels) of pages of a certain page (for example, pages with ID 93), then for such a trick we can use the get_pages () function:

ID; $ args = array ("title_li" => "Parent page tree:". $ parent, "include" => $ parent. ",". implode (",", $ pageids)); wp_list_pages ($ args); )?>

# 5 labeling and styling lists of persistent pages

Default, wp_list_pages () creates a list like this:

If we remove the title by setting an empty parameter title_li =, then the view will become like this:

...

In another way, you can write like this:

All li tags created by the function wp_list_pages () tagged with CSS class page_item. When the page you are on appears in the list, the current_page_parent class is added to the li element of the list.

Thus, the list can be "colored" with the following CSS selectors:

Pagenav (…) / * the main class of the ul tag that wraps the entire list * / .page-item-2 (…) / * the item related to the page with ID 2 * / .page_item (…) / * any item in the list * /. current_page_item (...) / * current page * / .current_page_parent (...) / * parent page of the current * / .current_page_ancestor (...) / * any page as related to the current one (parent or daughter.) * /

To achieve global impact on list items, use the following selectors:

Pagenav ul ul, .pagenav .current_page_item ul ul, .pagenav .current_page_ancestor ul ul, .pagenav .current_page_ancestor .current_page_item ul, .pagenav .current_page_ancestor .current_page_ancestor ul ul (display: nonerent;) .pagenav. Ul .pagenav. Ul. current_page_ancestor ul, .pagenav .current_page_ancestor .current_page_item ul, .pagenav .current_page_ancestor .current_page_ancestor ul, .pagenav .current_page_ page

# 6. List of sibling or child pages to the current one

post_parent) (// collect related pages $ relations = get_post_ancestors ($ post-> ID); // get child pages (if any) $ result = $ wpdb-> get_results ("SELECT ID FROM wp_posts WHERE post_parent = $ post-> ID AND post_type = "page" "); // if the child pages of this page turned out // get merge them with related ones if ($ result) (foreach ($ result as $ pageID) (array_push ($ relations, $ pageID-> ID );)) // add the current page to siblings array_push ($ relations, $ post-> ID); // make a comma-separated list of siblings, child and current IDs $ relations_string = implode (",", $ relations); / / get the list using the include parameter $ sidelinks = wp_list_pages ("title_li = & echo = 0 & include =". $ relations_string);) // if it's not a child page else (// show only child pages one level $ sidelinks = wp_list_pages ("title_li = & echo = 0 & depth = 1 & child_of = ". $ post-> ID);) if ($ sidelinks) (?>

    echo $ sidelinks tags; ?>

# 7 Using a custom post type (other than page)

If an arbitrary post type with a tree structure is created on the site, then wp_list_pages () can be used to display such records as well.

In general, all the above examples are suitable for this case as well, the only thing is to change the type of record with which the function will work.

The post type is specified in the post_type parameter:

Wp_list_pages (array ("post_type" => "portfolio", "title_li" => __ ("Portfolio")));

Notes

  • Since version 2.7 the following parameters have been added: link_before, link_after and exclude_tree.
  • Since version 2.8, the following parameters have been added: number and offset.

Do you want to get really live subscribers to your Telegram channel, but don't know where to do it? Follow the link and buy the necessary resource at incredibly cheap prices. You will also have access to wholesale discounts for faster and more efficient channel promotion.

Code wp list pages: wp-includes / post-template.php WP 5.2.1

0, "show_date" => "", "date_format" => get_option ("date_format"), "child_of" => 0, "exclude" => "", "title_li" => __ ("Pages"), " echo "=> 1," authors "=>" "," sort_column "=>" menu_order, post_title "," link_before "=>" "," link_after "=>" "," item_spacing "=>" preserve ", "walker" => "",); $ r = wp_parse_args ($ args, $ defaults); if (! in_array ($ r ["item_spacing"], array ("preserve", "discard"), true)) (// invalid value, fall back to default. $ r ["item_spacing"] = $ defaults [" item_spacing "];) $ output =" "; $ current_page = 0; // sanitize, mostly to keep spaces out $ r ["exclude"] = preg_replace ("/ [^ 0-9,] /", "", $ r ["exclude"]); // Allow plugins to filter an array of excluded pages (but don "t put a nullstring into the array) $ exclude_array = ($ r [" exclude "])? Explode (", ", $ r [" exclude "]) : array (); / ** * Filters the array of pages to exclude from the pages list. * * @since 2.1.0 * * @param array $ exclude_array An array of page IDs to exclude. * / $ r ["exclude "] = implode (", ", apply_filters (" wp_list_pages_excludes ", $ exclude_array)); // Query pages. $ r [" hierarchical "] = 0; $ pages = get_pages ($ r); if (! empty ($ pages)) (if ($ r ["title_li"]) ($ output. = " ";)) / ** * Filters the HTML output of the pages to list. * * @Since 1.5.1 * @since 4.4.0` $ pages` added as arguments. * * @See wp_list_pages () * * @param string $ output HTML output of the pages list. * @param array $ r An array of page-listing arguments. * @param array $ pages List of WP_Post objects returned by `get_pages ()` * / $ html = apply_filters ("wp_list_pages ", $ output, $ r, $ pages); if ($ r [" echo "]) (echo $ html;) else (return $ html;))

Most of the corporate and classic sites created on WordPress use pages rather than posts for content. Static pages contain information about the company, employees, services of the company and the like. At the same time, the ability to display the list of pages is limited only by the standard menu functionality. Yes, you can use the wp_nav_menu function with different parameters, but for beginners it is not very simple and not very intuitive. In such cases, the Page-list plugin comes to your aid.

The module allows you to display lists of pages using shortcodes. In this case, you can specify certain parameters for display, for example, show thumbnails for pages.

Installing the Page-list module is quite simple. After activation, you do not need to configure anything further. In order to display a list of pages, write in some kind of WordPress text block. This could be a blog post, page, or sidebar widget. If the shortcode in the widget does not work, then you need to add the line to functions.php:

Add_filter ("widget_text", "do_shortcode");

Shortcode lists all pages.

In the picture above, you can see that the shortcode has special parameters. With their help, any user can display the set of pages he needs. The example used: child_of (the ID of the parent page to display its subpages), exclude (excluding certain pages), and depth (the number of levels of the page hierarchy to display).

As for shortcodes, there are only 4 of them:

  • - a list of all pages of the site;
  • - list of subpages of the current page;
  • - a list of subpages that have the same parent page with the current one;
  • - a list of pages with illustrators and descriptions;

Shortcodes and very interesting for corporate sites. In theory, they can be used to make a context-sensitive menu. This is when you go to any of the menu items with subpages and see their list in the sidebar.

A very popular option on classic sites. As for the shortcode then this is generally just a find. With it, you can organize a simple product catalog on your pages. The function displays an image of the page and a short description of it. You can even set the number of characters in the text and the size of the picture.

To display such a list, use the following shortcode:

As I said above, you can limit the length of the description text:

Or remove the short announcement altogether:

Hello dear friends! Max Metelev speaks to you in open mode and tells and shows in practice.

And today, for a snack in the morning, a portion of useful material of the following content - we will learn how to display a list of wordpress pages with pictures. The lesson is very simple and interesting. Go.

Most websites primarily use pages for text content. Since pages are different from posts, you may need methods to display them.

In addition to the basic way of displaying wordpress pages with previews, we will show you how to display child pages and parent pages.

It will look something like this:

The first thing you need to do is install and activate the Page-list plugin. It works right out of the box, so we won't go into the settings, since they are not there.

This plugin comes with a list of shortcodes with an extensive list of parameters. Let's start by making a simple display of all pages of the site, that is, we will make a regular map

Create a new page in WordPress and add the following shortcode to it [pagelist]

This shortcode will show a simple nest of all your pages.

You can use either this or a number of other text widgets. If they do not work for you on the site, then you need to connect them by adding a line in the file functions. php your theme or to a specific section of the plugin.

add_filter ("widget_text", "do_shortcode");

add_filter ("widget_text", "do_shortcode");

Displaying child pages for a parent in WordPress

All you need to do is add the desired shortcode. [subpages] to the parent's page.

Also you can use shortcodes to insert into text widgets.

Adding related pages to WordPress

Sibling pages are essentially child pages that have one common parent. The output of such wordpress pages is carried out using the following construction [siblings]

Displaying pages with previews and a snippet of text

The Page-list plugin comes with the following code [page_ext]... This embed code gives advanced options for displaying page lists in WordPress.

You can use it to display a page structure with a characteristic image of an article and a small snippet of text from it. Like here:

[pagelist_ext show_image = "1" image_width = "50"]

You can set the image size yourself using the parameter image_width

Also, you can control the length of a piece of text using the parameter limit_content

For example, you can set 100 characters, for example [pagelist_ext limit_content = "100"]

If you do not want to display text near the article thumbnail, then use the following shortcode for the page [pagelist_ext show_content = "0"]

Thank you for your attention and happy studying!

WordPress pages are also pages - this is stationary information posted on the site, which is not associated with the release dates of posts, nor with the main page of the site, nor with the site headings.

WordPress page structure

WordPress pages are not linked to and no tags are assigned to pages. However, pages, like headings, can be arranged in a hierarchy, such as Parent page -> Page.

The URL of the child page will be like this:

http://example.ru/Parent page / Page.

Editing a page

Page editing is carried out on the tab Pages → Add New or Pages -> All Pages -> Edit... Editing a page is similar to editing posts. The page has a title, text, and metadata.

The hierarchy of pages is set in the "Attributes" field. In the list of pages, you can also edit them: change (1), delete (2), change properties (3).

Pages and menus

The page can be included in the menu, but it is not a menu item and does not participate in the organization of site navigation.

An example of a page on a menu is a sitemap. All plugins to create for a visitor involve creating a separate page with a sitemap shortcode.

To include a page in the menu, open the tab Appearance → Menu... Select or create a new menu and on the left side select the pages you want to add to the menu and add them. After saving, the links to the pages will be displayed on the site in this menu.

How to show pages on the site

To display pages on the site, you can use the widget ( Appearance → Widgets): Pages widget. This widget will show you a list of all pages on your site.

WordPress pages in code and template files

The work template page template is the page.php file. To edit it you need to open the site editor, tab Appearance -> Editor and find the page.php file there.

If you have it installed, then you can separately, the tab Appearance -> CSS Editor... These changes will not disappear when the template is updated.

Many modern WordPress templates support changing the page template separately, and these settings are available on the page creation tabs.

Conclusion

A page is a unique type of information on a WordPress site that is not “subject” to the time and basic structure of the site.

Igor Serov specially for the site ""

Most business websites most often use pages to host their content. Since pages are different from posts, you may need different ways to display them. In this article, we will show you how easy it is to add a thumbnail page list in WordPress. We will also show you how to display child and sibling pages.

First thing you need to do is install and activate the Page-list plugin. It works out of the box ”does not need any additional configuration.

Page-list has shortcodes with a huge number of parameters available. Let's start by adding a simple list of all pages in the form of a sitemap.

Just create a new page in WordPress and add a shortcode to it .

This shortcode will display a simple nested list of all your pages.

You can use this or any other shortcode in WordPress text widgets. If shortcodes do not work in widgets on your site, then you need to activate their support. Add the following line to your theme's functions.php file or to:

Add_filter ("widget_text", "do_shortcode");

Displaying child pages for a parent in WordPress

Earlier in our article, we showed you different ways to display child pages on a parent page in WordPress. Page-list makes displaying child pages much easier.

All you have to do is add a shortcode to the parent page.

Also you can use shortcode in text widget.

Displaying siblings on WordPress pages

Siblings are child pages that share the same parent page. You can display sibling pages using a shortcode on a page or inside a widget.

Displaying a list of pages with a thumbnail and a quote

There is another shortcode in the Page-list plugin - ... This shortcode provides advanced options for listing your pages in WordPress.

You can use it to list pages with thumbnail and quote. For example, like this:

You can also adjust the image size by using the parameter image_width.

It is possible to control the length of the quote using the parameter limit_content inside the shortcode.

If you do not want to display a short quote, you can disable it by using the parameter show_content inside the shortcode.

For a more complete list of options, take a look at the complete list of parameters that you can use in this shortcode.

We hope this article helped you to easily list thumbnail pages in WordPress.

For all questions and feedback, please write in the comments below.



Did you like the article? Share it