7 * @package WordPress |
7 * @package WordPress |
8 * @subpackage Template |
8 * @subpackage Template |
9 */ |
9 */ |
10 |
10 |
11 /** |
11 /** |
12 * Display the ID of the current item in the WordPress Loop. |
12 * Displays the ID of the current item in the WordPress Loop. |
13 * |
13 * |
14 * @since 0.71 |
14 * @since 0.71 |
15 */ |
15 */ |
16 function the_ID() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid |
16 function the_ID() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid |
17 echo get_the_ID(); |
17 echo get_the_ID(); |
18 } |
18 } |
19 |
19 |
20 /** |
20 /** |
21 * Retrieve the ID of the current item in the WordPress Loop. |
21 * Retrieves the ID of the current item in the WordPress Loop. |
22 * |
22 * |
23 * @since 2.1.0 |
23 * @since 2.1.0 |
24 * |
24 * |
25 * @return int|false The ID of the current item in the WordPress Loop. False if $post is not set. |
25 * @return int|false The ID of the current item in the WordPress Loop. False if $post is not set. |
26 */ |
26 */ |
28 $post = get_post(); |
28 $post = get_post(); |
29 return ! empty( $post ) ? $post->ID : false; |
29 return ! empty( $post ) ? $post->ID : false; |
30 } |
30 } |
31 |
31 |
32 /** |
32 /** |
33 * Display or retrieve the current post title with optional markup. |
33 * Displays or retrieves the current post title with optional markup. |
34 * |
34 * |
35 * @since 0.71 |
35 * @since 0.71 |
36 * |
36 * |
37 * @param string $before Optional. Markup to prepend to the title. Default empty. |
37 * @param string $before Optional. Markup to prepend to the title. Default empty. |
38 * @param string $after Optional. Markup to append to the title. Default empty. |
38 * @param string $after Optional. Markup to append to the title. Default empty. |
54 return $title; |
54 return $title; |
55 } |
55 } |
56 } |
56 } |
57 |
57 |
58 /** |
58 /** |
59 * Sanitize the current title when retrieving or displaying. |
59 * Sanitizes the current title when retrieving or displaying. |
60 * |
60 * |
61 * Works like the_title(), except the parameters can be in a string or |
61 * Works like the_title(), except the parameters can be in a string or |
62 * an array. See the function for what can be override in the $args parameter. |
62 * an array. See the function for what can be override in the $args parameter. |
63 * |
63 * |
64 * The title before it is displayed will have the tags stripped and esc_attr() |
64 * The title before it is displayed will have the tags stripped and esc_attr() |
101 return $title; |
101 return $title; |
102 } |
102 } |
103 } |
103 } |
104 |
104 |
105 /** |
105 /** |
106 * Retrieve post title. |
106 * Retrieves the post title. |
107 * |
107 * |
108 * If the post is protected and the visitor is not an admin, then "Protected" |
108 * If the post is protected and the visitor is not an admin, then "Protected" |
109 * will be displayed before the post title. If the post is private, then |
109 * will be inserted before the post title. If the post is private, then |
110 * "Private" will be located before the post title. |
110 * "Private" will be inserted before the post title. |
111 * |
111 * |
112 * @since 0.71 |
112 * @since 0.71 |
113 * |
113 * |
114 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. |
114 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. |
115 * @return string |
115 * @return string |
170 */ |
170 */ |
171 return apply_filters( 'the_title', $title, $id ); |
171 return apply_filters( 'the_title', $title, $id ); |
172 } |
172 } |
173 |
173 |
174 /** |
174 /** |
175 * Display the Post Global Unique Identifier (guid). |
175 * Displays the Post Global Unique Identifier (guid). |
176 * |
176 * |
177 * The guid will appear to be a link, but should not be used as a link to the |
177 * The guid will appear to be a link, but should not be used as a link to the |
178 * post. The reason you should not use it as a link, is because of moving the |
178 * post. The reason you should not use it as a link, is because of moving the |
179 * blog across domains. |
179 * blog across domains. |
180 * |
180 * |
202 */ |
202 */ |
203 echo apply_filters( 'the_guid', $guid, $id ); |
203 echo apply_filters( 'the_guid', $guid, $id ); |
204 } |
204 } |
205 |
205 |
206 /** |
206 /** |
207 * Retrieve the Post Global Unique Identifier (guid). |
207 * Retrieves the Post Global Unique Identifier (guid). |
208 * |
208 * |
209 * The guid will appear to be a link, but should not be used as an link to the |
209 * The guid will appear to be a link, but should not be used as an link to the |
210 * post. The reason you should not use it as a link, is because of moving the |
210 * post. The reason you should not use it as a link, is because of moving the |
211 * blog across domains. |
211 * blog across domains. |
212 * |
212 * |
231 */ |
231 */ |
232 return apply_filters( 'get_the_guid', $guid, $id ); |
232 return apply_filters( 'get_the_guid', $guid, $id ); |
233 } |
233 } |
234 |
234 |
235 /** |
235 /** |
236 * Display the post content. |
236 * Displays the post content. |
237 * |
237 * |
238 * @since 0.71 |
238 * @since 0.71 |
239 * |
239 * |
240 * @param string $more_link_text Optional. Content for when there is more text. |
240 * @param string $more_link_text Optional. Content for when there is more text. |
241 * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default false. |
241 * @param bool $strip_teaser Optional. Strip teaser content before the more text. Default false. |
254 $content = str_replace( ']]>', ']]>', $content ); |
254 $content = str_replace( ']]>', ']]>', $content ); |
255 echo $content; |
255 echo $content; |
256 } |
256 } |
257 |
257 |
258 /** |
258 /** |
259 * Retrieve the post content. |
259 * Retrieves the post content. |
260 * |
260 * |
261 * @since 0.71 |
261 * @since 0.71 |
262 * @since 5.2.0 Added the `$post` parameter. |
262 * @since 5.2.0 Added the `$post` parameter. |
263 * |
263 * |
264 * @global int $page Page number of a single post/page. |
264 * @global int $page Page number of a single post/page. |
837 |
837 |
838 return array_unique( $classes ); |
838 return array_unique( $classes ); |
839 } |
839 } |
840 |
840 |
841 /** |
841 /** |
842 * Whether post requires password and correct password has been provided. |
842 * Determines whether the post requires password and whether a correct password has been provided. |
843 * |
843 * |
844 * @since 2.7.0 |
844 * @since 2.7.0 |
845 * |
845 * |
846 * @param int|WP_Post|null $post An optional post. Global $post used if not provided. |
846 * @param int|WP_Post|null $post An optional post. Global $post used if not provided. |
847 * @return bool false if a password is not required or the correct password cookie is present, true otherwise. |
847 * @return bool false if a password is not required or the correct password cookie is present, true otherwise. |
1003 /** |
1003 /** |
1004 * Filters the HTML output of page links for paginated posts. |
1004 * Filters the HTML output of page links for paginated posts. |
1005 * |
1005 * |
1006 * @since 3.6.0 |
1006 * @since 3.6.0 |
1007 * |
1007 * |
1008 * @param string $output HTML output of paginated posts' page links. |
1008 * @param string $output HTML output of paginated posts' page links. |
1009 * @param array $args An array of arguments. See wp_link_pages() |
1009 * @param array|string $args An array or query string of arguments. See wp_link_pages() |
1010 * for information on accepted arguments. |
1010 * for information on accepted arguments. |
1011 */ |
1011 */ |
1012 $html = apply_filters( 'wp_link_pages', $output, $args ); |
1012 $html = apply_filters( 'wp_link_pages', $output, $args ); |
1013 |
1013 |
1014 if ( $parsed_args['echo'] ) { |
1014 if ( $parsed_args['echo'] ) { |
1015 echo $html; |
1015 echo $html; |
1082 return $custom[ $key ]; |
1082 return $custom[ $key ]; |
1083 } |
1083 } |
1084 } |
1084 } |
1085 |
1085 |
1086 /** |
1086 /** |
1087 * Display a list of post custom fields. |
1087 * Displays a list of post custom fields. |
1088 * |
1088 * |
1089 * @since 1.2.0 |
1089 * @since 1.2.0 |
1090 * |
1090 * |
1091 * @internal This will probably change at some point... |
1091 * @deprecated 6.0.2 Use get_post_meta() to retrieve post meta and render manually. |
1092 */ |
1092 */ |
1093 function the_meta() { |
1093 function the_meta() { |
|
1094 _deprecated_function( __FUNCTION__, '6.0.2', 'get_post_meta()' ); |
1094 $keys = get_post_custom_keys(); |
1095 $keys = get_post_custom_keys(); |
1095 if ( $keys ) { |
1096 if ( $keys ) { |
1096 $li_html = ''; |
1097 $li_html = ''; |
1097 foreach ( (array) $keys as $key ) { |
1098 foreach ( (array) $keys as $key ) { |
1098 $keyt = trim( $key ); |
1099 $keyt = trim( $key ); |
1104 $value = implode( ', ', $values ); |
1105 $value = implode( ', ', $values ); |
1105 |
1106 |
1106 $html = sprintf( |
1107 $html = sprintf( |
1107 "<li><span class='post-meta-key'>%s</span> %s</li>\n", |
1108 "<li><span class='post-meta-key'>%s</span> %s</li>\n", |
1108 /* translators: %s: Post custom field name. */ |
1109 /* translators: %s: Post custom field name. */ |
1109 sprintf( _x( '%s:', 'Post custom field name' ), $key ), |
1110 esc_html( sprintf( _x( '%s:', 'Post custom field name' ), $key ) ), |
1110 $value |
1111 esc_html( $value ) |
1111 ); |
1112 ); |
1112 |
1113 |
1113 /** |
1114 /** |
1114 * Filters the HTML output of the li element in the post custom fields list. |
1115 * Filters the HTML output of the li element in the post custom fields list. |
1115 * |
1116 * |
1257 * 'menu_order', 'post_parent', 'ID', 'rand', or 'comment_count'. Default 'post_title'. |
1258 * 'menu_order', 'post_parent', 'ID', 'rand', or 'comment_count'. Default 'post_title'. |
1258 * @type string $title_li List heading. Passing a null or empty value will result in no heading, and the list |
1259 * @type string $title_li List heading. Passing a null or empty value will result in no heading, and the list |
1259 * will not be wrapped with unordered list `<ul>` tags. Default 'Pages'. |
1260 * will not be wrapped with unordered list `<ul>` tags. Default 'Pages'. |
1260 * @type string $item_spacing Whether to preserve whitespace within the menu's HTML. Accepts 'preserve' or 'discard'. |
1261 * @type string $item_spacing Whether to preserve whitespace within the menu's HTML. Accepts 'preserve' or 'discard'. |
1261 * Default 'preserve'. |
1262 * Default 'preserve'. |
1262 * @type Walker $walker Walker instance to use for listing pages. Default empty (Walker_Page). |
1263 * @type Walker $walker Walker instance to use for listing pages. Default empty which results in a |
|
1264 * Walker_Page instance being used. |
1263 * } |
1265 * } |
1264 * @return void|string Void if 'echo' argument is true, HTML list of pages if 'echo' is false. |
1266 * @return void|string Void if 'echo' argument is true, HTML list of pages if 'echo' is false. |
1265 */ |
1267 */ |
1266 function wp_list_pages( $args = '' ) { |
1268 function wp_list_pages( $args = '' ) { |
1267 $defaults = array( |
1269 $defaults = array( |
1379 * @type string $link_after The HTML or text to append to $show_home text. Default empty. |
1381 * @type string $link_after The HTML or text to append to $show_home text. Default empty. |
1380 * @type string $before The HTML or text to prepend to the menu. Default is '<ul>'. |
1382 * @type string $before The HTML or text to prepend to the menu. Default is '<ul>'. |
1381 * @type string $after The HTML or text to append to the menu. Default is '</ul>'. |
1383 * @type string $after The HTML or text to append to the menu. Default is '</ul>'. |
1382 * @type string $item_spacing Whether to preserve whitespace within the menu's HTML. Accepts 'preserve' |
1384 * @type string $item_spacing Whether to preserve whitespace within the menu's HTML. Accepts 'preserve' |
1383 * or 'discard'. Default 'discard'. |
1385 * or 'discard'. Default 'discard'. |
1384 * @type Walker $walker Walker instance to use for listing pages. Default empty (Walker_Page). |
1386 * @type Walker $walker Walker instance to use for listing pages. Default empty which results in a |
|
1387 * Walker_Page instance being used. |
1385 * } |
1388 * } |
1386 * @return void|string Void if 'echo' argument is true, HTML menu if 'echo' is false. |
1389 * @return void|string Void if 'echo' argument is true, HTML menu if 'echo' is false. |
1387 */ |
1390 */ |
1388 function wp_page_menu( $args = array() ) { |
1391 function wp_page_menu( $args = array() ) { |
1389 $defaults = array( |
1392 $defaults = array( |
1511 // |
1514 // |
1512 // Page helpers. |
1515 // Page helpers. |
1513 // |
1516 // |
1514 |
1517 |
1515 /** |
1518 /** |
1516 * Retrieve HTML list content for page list. |
1519 * Retrieves HTML list content for page list. |
1517 * |
1520 * |
1518 * @uses Walker_Page to create HTML list content. |
1521 * @uses Walker_Page to create HTML list content. |
1519 * @since 2.1.0 |
1522 * @since 2.1.0 |
1520 * |
1523 * |
1521 * @param array $pages |
1524 * @param array $pages |
1522 * @param int $depth |
1525 * @param int $depth |
1523 * @param int $current_page |
1526 * @param int $current_page |
1524 * @param array $r |
1527 * @param array $args |
1525 * @return string |
1528 * @return string |
1526 */ |
1529 */ |
1527 function walk_page_tree( $pages, $depth, $current_page, $r ) { |
1530 function walk_page_tree( $pages, $depth, $current_page, $args ) { |
1528 if ( empty( $r['walker'] ) ) { |
1531 if ( empty( $args['walker'] ) ) { |
1529 $walker = new Walker_Page; |
1532 $walker = new Walker_Page; |
1530 } else { |
1533 } else { |
1531 /** |
1534 /** |
1532 * @var Walker $walker |
1535 * @var Walker $walker |
1533 */ |
1536 */ |
1534 $walker = $r['walker']; |
1537 $walker = $args['walker']; |
1535 } |
1538 } |
1536 |
1539 |
1537 foreach ( (array) $pages as $page ) { |
1540 foreach ( (array) $pages as $page ) { |
1538 if ( $page->post_parent ) { |
1541 if ( $page->post_parent ) { |
1539 $r['pages_with_children'][ $page->post_parent ] = true; |
1542 $args['pages_with_children'][ $page->post_parent ] = true; |
1540 } |
1543 } |
1541 } |
1544 } |
1542 |
1545 |
1543 return $walker->walk( $pages, $depth, $r, $current_page ); |
1546 return $walker->walk( $pages, $depth, $args, $current_page ); |
1544 } |
1547 } |
1545 |
1548 |
1546 /** |
1549 /** |
1547 * Retrieve HTML dropdown (select) content for page list. |
1550 * Retrieves HTML dropdown (select) content for page list. |
1548 * |
1551 * |
1549 * @since 2.1.0 |
1552 * @since 2.1.0 |
1550 * @since 5.3.0 Formalized the existing `...$args` parameter by adding it |
1553 * @since 5.3.0 Formalized the existing `...$args` parameter by adding it |
1551 * to the function signature. |
1554 * to the function signature. |
1552 * |
1555 * |
1594 echo wp_get_attachment_link( $id, 'thumbnail', $permalink ); |
1597 echo wp_get_attachment_link( $id, 'thumbnail', $permalink ); |
1595 } |
1598 } |
1596 } |
1599 } |
1597 |
1600 |
1598 /** |
1601 /** |
1599 * Retrieve an attachment page link using an image or icon, if possible. |
1602 * Retrieves an attachment page link using an image or icon, if possible. |
1600 * |
1603 * |
1601 * @since 2.5.0 |
1604 * @since 2.5.0 |
1602 * @since 4.4.0 The `$id` parameter can now accept either a post ID or `WP_Post` object. |
1605 * @since 4.4.0 The `$id` parameter can now accept either a post ID or `WP_Post` object. |
1603 * |
1606 * |
1604 * @param int|WP_Post $id Optional. Post ID or post object. |
1607 * @param int|WP_Post $id Optional. Post ID or post object. |
1644 * |
1647 * |
1645 * @since 2.7.0 |
1648 * @since 2.7.0 |
1646 * @since 5.1.0 Added the `$attr` parameter. |
1649 * @since 5.1.0 Added the `$attr` parameter. |
1647 * |
1650 * |
1648 * @param string $link_html The page link HTML output. |
1651 * @param string $link_html The page link HTML output. |
1649 * @param int $id Post ID. |
1652 * @param int|WP_Post $id Post ID or object. Can be 0 for the current global post. |
1650 * @param string|int[] $size Requested image size. Can be any registered image size name, or |
1653 * @param string|int[] $size Requested image size. Can be any registered image size name, or |
1651 * an array of width and height values in pixels (in that order). |
1654 * an array of width and height values in pixels (in that order). |
1652 * @param bool $permalink Whether to add permalink to image. Default false. |
1655 * @param bool $permalink Whether to add permalink to image. Default false. |
1653 * @param bool $icon Whether to include an icon. |
1656 * @param bool $icon Whether to include an icon. |
1654 * @param string|false $text If string, will be link text. |
1657 * @param string|false $text If string, will be link text. |
1656 */ |
1659 */ |
1657 return apply_filters( 'wp_get_attachment_link', "<a href='" . esc_url( $url ) . "'>$link_text</a>", $id, $size, $permalink, $icon, $text, $attr ); |
1660 return apply_filters( 'wp_get_attachment_link', "<a href='" . esc_url( $url ) . "'>$link_text</a>", $id, $size, $permalink, $icon, $text, $attr ); |
1658 } |
1661 } |
1659 |
1662 |
1660 /** |
1663 /** |
1661 * Wrap attachment in paragraph tag before content. |
1664 * Wraps attachment in paragraph tag before content. |
1662 * |
1665 * |
1663 * @since 2.0.0 |
1666 * @since 2.0.0 |
1664 * |
1667 * |
1665 * @param string $content |
1668 * @param string $content |
1666 * @return string |
1669 * @return string |
1741 */ |
1744 */ |
1742 return apply_filters( 'the_password_form', $output, $post ); |
1745 return apply_filters( 'the_password_form', $output, $post ); |
1743 } |
1746 } |
1744 |
1747 |
1745 /** |
1748 /** |
1746 * Determines whether currently in a page template. |
1749 * Determines whether the current post uses a page template. |
1747 * |
1750 * |
1748 * This template tag allows you to determine if you are in a page template. |
1751 * This template tag allows you to determine if you are in a page template. |
1749 * You can optionally provide a template filename or array of template filenames |
1752 * You can optionally provide a template filename or array of template filenames |
1750 * and then the check will be specific to that template. |
1753 * and then the check will be specific to that template. |
1751 * |
1754 * |
1785 |
1788 |
1786 return ( 'default' === $template && ! $page_template ); |
1789 return ( 'default' === $template && ! $page_template ); |
1787 } |
1790 } |
1788 |
1791 |
1789 /** |
1792 /** |
1790 * Get the specific template filename for a given post. |
1793 * Gets the specific template filename for a given post. |
1791 * |
1794 * |
1792 * @since 3.4.0 |
1795 * @since 3.4.0 |
1793 * @since 4.7.0 Now works with any post type, not just pages. |
1796 * @since 4.7.0 Now works with any post type, not just pages. |
1794 * |
1797 * |
1795 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. |
1798 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. |
1916 */ |
1919 */ |
1917 return apply_filters( 'wp_post_revision_title_expanded', $revision_date_author, $revision, $link ); |
1920 return apply_filters( 'wp_post_revision_title_expanded', $revision_date_author, $revision, $link ); |
1918 } |
1921 } |
1919 |
1922 |
1920 /** |
1923 /** |
1921 * Display a list of a post's revisions. |
1924 * Displays a list of a post's revisions. |
1922 * |
1925 * |
1923 * Can output either a UL with edit links or a TABLE with diff interface, and |
1926 * Can output either a UL with edit links or a TABLE with diff interface, and |
1924 * restore action links. |
1927 * restore action links. |
1925 * |
1928 * |
1926 * @since 2.6.0 |
1929 * @since 2.6.0 |