94 * will be displayed before the post title. If the post is private, then |
102 * will be displayed before the post title. If the post is private, then |
95 * "Private" will be located before the post title. |
103 * "Private" will be located before the post title. |
96 * |
104 * |
97 * @since 0.71 |
105 * @since 0.71 |
98 * |
106 * |
99 * @param int|object $post Optional. Post ID or object. |
107 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. |
100 * @return string |
108 * @return string |
101 */ |
109 */ |
102 function get_the_title( $post = 0 ) { |
110 function get_the_title( $post = 0 ) { |
103 $post = get_post( $post ); |
111 $post = get_post( $post ); |
104 |
112 |
105 $title = isset( $post->post_title ) ? $post->post_title : ''; |
113 $title = isset( $post->post_title ) ? $post->post_title : ''; |
106 $id = isset( $post->ID ) ? $post->ID : 0; |
114 $id = isset( $post->ID ) ? $post->ID : 0; |
107 |
115 |
108 if ( ! is_admin() ) { |
116 if ( ! is_admin() ) { |
109 if ( ! empty( $post->post_password ) ) { |
117 if ( ! empty( $post->post_password ) ) { |
110 $protected_title_format = apply_filters( 'protected_title_format', __( 'Protected: %s' ) ); |
118 |
|
119 /** |
|
120 * Filter the text prepended to the post title for protected posts. |
|
121 * |
|
122 * The filter is only applied on the front end. |
|
123 * |
|
124 * @since 2.8.0 |
|
125 * |
|
126 * @param string $prepend Text displayed before the post title. |
|
127 * Default 'Protected: %s'. |
|
128 * @param WP_Post $post Current post object. |
|
129 */ |
|
130 $protected_title_format = apply_filters( 'protected_title_format', __( 'Protected: %s' ), $post ); |
111 $title = sprintf( $protected_title_format, $title ); |
131 $title = sprintf( $protected_title_format, $title ); |
112 } else if ( isset( $post->post_status ) && 'private' == $post->post_status ) { |
132 } elseif ( isset( $post->post_status ) && 'private' == $post->post_status ) { |
113 $private_title_format = apply_filters( 'private_title_format', __( 'Private: %s' ) ); |
133 |
|
134 /** |
|
135 * Filter the text prepended to the post title of private posts. |
|
136 * |
|
137 * The filter is only applied on the front end. |
|
138 * |
|
139 * @since 2.8.0 |
|
140 * |
|
141 * @param string $prepend Text displayed before the post title. |
|
142 * Default 'Private: %s'. |
|
143 * @param WP_Post $post Current post object. |
|
144 */ |
|
145 $private_title_format = apply_filters( 'private_title_format', __( 'Private: %s' ), $post ); |
114 $title = sprintf( $private_title_format, $title ); |
146 $title = sprintf( $private_title_format, $title ); |
115 } |
147 } |
116 } |
148 } |
117 |
149 |
|
150 /** |
|
151 * Filter the post title. |
|
152 * |
|
153 * @since 0.71 |
|
154 * |
|
155 * @param string $title The post title. |
|
156 * @param int $id The post ID. |
|
157 */ |
118 return apply_filters( 'the_title', $title, $id ); |
158 return apply_filters( 'the_title', $title, $id ); |
119 } |
159 } |
120 |
160 |
121 /** |
161 /** |
122 * Display the Post Global Unique Identifier (guid). |
162 * Display the Post Global Unique Identifier (guid). |
292 * Display the classes for the post div. |
384 * Display the classes for the post div. |
293 * |
385 * |
294 * @since 2.7.0 |
386 * @since 2.7.0 |
295 * |
387 * |
296 * @param string|array $class One or more classes to add to the class list. |
388 * @param string|array $class One or more classes to add to the class list. |
297 * @param int $post_id An optional post ID. |
389 * @param int|WP_Post $post_id Optional. Post ID or post object. |
298 */ |
390 */ |
299 function post_class( $class = '', $post_id = null ) { |
391 function post_class( $class = '', $post_id = null ) { |
300 // Separates classes with a single space, collates classes for post DIV |
392 // Separates classes with a single space, collates classes for post DIV |
301 echo 'class="' . join( ' ', get_post_class( $class, $post_id ) ) . '"'; |
393 echo 'class="' . join( ' ', get_post_class( $class, $post_id ) ) . '"'; |
302 } |
394 } |
303 |
395 |
304 /** |
396 /** |
305 * Retrieve the classes for the post div as an array. |
397 * Retrieve the classes for the post div as an array. |
306 * |
398 * |
307 * The class names are add are many. If the post is a sticky, then the 'sticky' |
399 * The class names are many. If the post is a sticky, then the 'sticky' |
308 * class name. The class 'hentry' is always added to each post. For each |
400 * class name. The class 'hentry' is always added to each post. If the post has a |
309 * category, the class will be added with 'category-' with category slug is |
401 * post thumbnail, 'has-post-thumbnail' is added as a class. For each taxonomy that |
310 * added. The tags are the same way as the categories with 'tag-' before the tag |
402 * the post belongs to, a class will be added of the format '{$taxonomy}-{$slug}' - |
311 * slug. All classes are passed through the filter, 'post_class' with the list |
403 * eg 'category-foo' or 'my_custom_taxonomy-bar'. The 'post_tag' taxonomy is a special |
312 * of classes, followed by $class parameter value, with the post ID as the last |
404 * case; the class has the 'tag-' prefix instead of 'post_tag-'. All classes are |
313 * parameter. |
405 * passed through the filter, 'post_class' with the list of classes, followed by |
|
406 * $class parameter value, with the post ID as the last parameter. |
314 * |
407 * |
315 * @since 2.7.0 |
408 * @since 2.7.0 |
316 * |
409 * @since 4.2.0 Custom taxonomy classes were added. |
317 * @param string|array $class One or more classes to add to the class list. |
410 * |
318 * @param int $post_id An optional post ID. |
411 * @param string|array $class One or more classes to add to the class list. |
|
412 * @param int|WP_Post $post_id Optional. Post ID or post object. |
319 * @return array Array of classes. |
413 * @return array Array of classes. |
320 */ |
414 */ |
321 function get_post_class( $class = '', $post_id = null ) { |
415 function get_post_class( $class = '', $post_id = null ) { |
322 $post = get_post($post_id); |
416 $post = get_post( $post_id ); |
323 |
417 |
324 $classes = array(); |
418 $classes = array(); |
325 |
419 |
326 if ( empty($post) ) |
420 if ( $class ) { |
|
421 if ( ! is_array( $class ) ) { |
|
422 $class = preg_split( '#\s+#', $class ); |
|
423 } |
|
424 $classes = array_map( 'esc_attr', $class ); |
|
425 } |
|
426 |
|
427 if ( ! $post ) { |
327 return $classes; |
428 return $classes; |
|
429 } |
328 |
430 |
329 $classes[] = 'post-' . $post->ID; |
431 $classes[] = 'post-' . $post->ID; |
330 if ( ! is_admin() ) |
432 if ( ! is_admin() ) |
331 $classes[] = $post->post_type; |
433 $classes[] = $post->post_type; |
332 $classes[] = 'type-' . $post->post_type; |
434 $classes[] = 'type-' . $post->post_type; |
340 $classes[] = 'format-' . sanitize_html_class( $post_format ); |
442 $classes[] = 'format-' . sanitize_html_class( $post_format ); |
341 else |
443 else |
342 $classes[] = 'format-standard'; |
444 $classes[] = 'format-standard'; |
343 } |
445 } |
344 |
446 |
345 // post requires password |
447 // Post requires password |
346 if ( post_password_required($post->ID) ) |
448 if ( post_password_required( $post->ID ) ) { |
347 $classes[] = 'post-password-required'; |
449 $classes[] = 'post-password-required'; |
|
450 // Post thumbnails |
|
451 } elseif ( ! is_attachment( $post ) && current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $post->ID ) ) { |
|
452 $classes[] = 'has-post-thumbnail'; |
|
453 } |
348 |
454 |
349 // sticky for Sticky Posts |
455 // sticky for Sticky Posts |
350 if ( is_sticky($post->ID) && is_home() && !is_paged() ) |
456 if ( is_sticky( $post->ID ) ) { |
351 $classes[] = 'sticky'; |
457 if ( is_home() && ! is_paged() ) { |
|
458 $classes[] = 'sticky'; |
|
459 } elseif ( is_admin() ) { |
|
460 $classes[] = 'status-sticky'; |
|
461 } |
|
462 } |
352 |
463 |
353 // hentry for hAtom compliance |
464 // hentry for hAtom compliance |
354 $classes[] = 'hentry'; |
465 $classes[] = 'hentry'; |
355 |
466 |
356 // Categories |
467 // All public taxonomies |
357 if ( is_object_in_taxonomy( $post->post_type, 'category' ) ) { |
468 $taxonomies = get_taxonomies( array( 'public' => true ) ); |
358 foreach ( (array) get_the_category($post->ID) as $cat ) { |
469 foreach ( (array) $taxonomies as $taxonomy ) { |
359 if ( empty($cat->slug ) ) |
470 if ( is_object_in_taxonomy( $post->post_type, $taxonomy ) ) { |
360 continue; |
471 foreach ( (array) get_the_terms( $post->ID, $taxonomy ) as $term ) { |
361 $classes[] = 'category-' . sanitize_html_class($cat->slug, $cat->term_id); |
472 if ( empty( $term->slug ) ) { |
362 } |
473 continue; |
363 } |
474 } |
364 |
475 |
365 // Tags |
476 $term_class = sanitize_html_class( $term->slug, $term->term_id ); |
366 if ( is_object_in_taxonomy( $post->post_type, 'post_tag' ) ) { |
477 if ( is_numeric( $term_class ) || ! trim( $term_class, '-' ) ) { |
367 foreach ( (array) get_the_tags($post->ID) as $tag ) { |
478 $term_class = $term->term_id; |
368 if ( empty($tag->slug ) ) |
479 } |
369 continue; |
480 |
370 $classes[] = 'tag-' . sanitize_html_class($tag->slug, $tag->term_id); |
481 // 'post_tag' uses the 'tag' prefix for backward compatibility. |
371 } |
482 if ( 'post_tag' == $taxonomy ) { |
372 } |
483 $classes[] = 'tag-' . $term_class; |
373 |
484 } else { |
374 if ( !empty($class) ) { |
485 $classes[] = sanitize_html_class( $taxonomy . '-' . $term_class, $taxonomy . '-' . $term->term_id ); |
375 if ( !is_array( $class ) ) |
486 } |
376 $class = preg_split('#\s+#', $class); |
487 } |
377 $classes = array_merge($classes, $class); |
488 } |
378 } |
489 } |
379 |
490 |
380 $classes = array_map('esc_attr', $classes); |
491 $classes = array_map( 'esc_attr', $classes ); |
381 |
492 |
382 return apply_filters('post_class', $classes, $class, $post->ID); |
493 /** |
|
494 * Filter the list of CSS classes for the current post. |
|
495 * |
|
496 * @since 2.7.0 |
|
497 * |
|
498 * @param array $classes An array of post classes. |
|
499 * @param string $class A comma-separated list of additional classes added to the post. |
|
500 * @param int $post_id The post ID. |
|
501 */ |
|
502 $classes = apply_filters( 'post_class', $classes, $class, $post->ID ); |
|
503 |
|
504 return array_unique( $classes ); |
383 } |
505 } |
384 |
506 |
385 /** |
507 /** |
386 * Display the classes for the body element. |
508 * Display the classes for the body element. |
387 * |
509 * |
460 $classes[] = 'post-type-archive'; |
582 $classes[] = 'post-type-archive'; |
461 $post_type = get_query_var( 'post_type' ); |
583 $post_type = get_query_var( 'post_type' ); |
462 if ( is_array( $post_type ) ) |
584 if ( is_array( $post_type ) ) |
463 $post_type = reset( $post_type ); |
585 $post_type = reset( $post_type ); |
464 $classes[] = 'post-type-archive-' . sanitize_html_class( $post_type ); |
586 $classes[] = 'post-type-archive-' . sanitize_html_class( $post_type ); |
465 } else if ( is_author() ) { |
587 } elseif ( is_author() ) { |
466 $author = $wp_query->get_queried_object(); |
588 $author = $wp_query->get_queried_object(); |
467 $classes[] = 'author'; |
589 $classes[] = 'author'; |
468 if ( isset( $author->user_nicename ) ) { |
590 if ( isset( $author->user_nicename ) ) { |
469 $classes[] = 'author-' . sanitize_html_class( $author->user_nicename, $author->ID ); |
591 $classes[] = 'author-' . sanitize_html_class( $author->user_nicename, $author->ID ); |
470 $classes[] = 'author-' . $author->ID; |
592 $classes[] = 'author-' . $author->ID; |
471 } |
593 } |
472 } elseif ( is_category() ) { |
594 } elseif ( is_category() ) { |
473 $cat = $wp_query->get_queried_object(); |
595 $cat = $wp_query->get_queried_object(); |
474 $classes[] = 'category'; |
596 $classes[] = 'category'; |
475 if ( isset( $cat->term_id ) ) { |
597 if ( isset( $cat->term_id ) ) { |
476 $classes[] = 'category-' . sanitize_html_class( $cat->slug, $cat->term_id ); |
598 $cat_class = sanitize_html_class( $cat->slug, $cat->term_id ); |
|
599 if ( is_numeric( $cat_class ) || ! trim( $cat_class, '-' ) ) { |
|
600 $cat_class = $cat->term_id; |
|
601 } |
|
602 |
|
603 $classes[] = 'category-' . $cat_class; |
477 $classes[] = 'category-' . $cat->term_id; |
604 $classes[] = 'category-' . $cat->term_id; |
478 } |
605 } |
479 } elseif ( is_tag() ) { |
606 } elseif ( is_tag() ) { |
480 $tags = $wp_query->get_queried_object(); |
607 $tag = $wp_query->get_queried_object(); |
481 $classes[] = 'tag'; |
608 $classes[] = 'tag'; |
482 if ( isset( $tags->term_id ) ) { |
609 if ( isset( $tag->term_id ) ) { |
483 $classes[] = 'tag-' . sanitize_html_class( $tags->slug, $tags->term_id ); |
610 $tag_class = sanitize_html_class( $tag->slug, $tag->term_id ); |
484 $classes[] = 'tag-' . $tags->term_id; |
611 if ( is_numeric( $tag_class ) || ! trim( $tag_class, '-' ) ) { |
|
612 $tag_class = $tag->term_id; |
|
613 } |
|
614 |
|
615 $classes[] = 'tag-' . $tag_class; |
|
616 $classes[] = 'tag-' . $tag->term_id; |
485 } |
617 } |
486 } elseif ( is_tax() ) { |
618 } elseif ( is_tax() ) { |
487 $term = $wp_query->get_queried_object(); |
619 $term = $wp_query->get_queried_object(); |
488 if ( isset( $term->term_id ) ) { |
620 if ( isset( $term->term_id ) ) { |
|
621 $term_class = sanitize_html_class( $term->slug, $term->term_id ); |
|
622 if ( is_numeric( $term_class ) || ! trim( $term_class, '-' ) ) { |
|
623 $term_class = $term->term_id; |
|
624 } |
|
625 |
489 $classes[] = 'tax-' . sanitize_html_class( $term->taxonomy ); |
626 $classes[] = 'tax-' . sanitize_html_class( $term->taxonomy ); |
490 $classes[] = 'term-' . sanitize_html_class( $term->slug, $term->term_id ); |
627 $classes[] = 'term-' . $term_class; |
491 $classes[] = 'term-' . $term->term_id; |
628 $classes[] = 'term-' . $term->term_id; |
492 } |
629 } |
493 } |
630 } |
494 } elseif ( is_page() ) { |
631 } elseif ( is_page() ) { |
495 $classes[] = 'page'; |
632 $classes[] = 'page'; |
581 return false; |
736 return false; |
582 |
737 |
583 if ( ! isset( $_COOKIE['wp-postpass_' . COOKIEHASH] ) ) |
738 if ( ! isset( $_COOKIE['wp-postpass_' . COOKIEHASH] ) ) |
584 return true; |
739 return true; |
585 |
740 |
586 require_once ABSPATH . 'wp-includes/class-phpass.php'; |
741 require_once ABSPATH . WPINC . '/class-phpass.php'; |
587 $hasher = new PasswordHash( 8, true ); |
742 $hasher = new PasswordHash( 8, true ); |
588 |
743 |
589 $hash = wp_unslash( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] ); |
744 $hash = wp_unslash( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] ); |
590 if ( 0 !== strpos( $hash, '$P$B' ) ) |
745 if ( 0 !== strpos( $hash, '$P$B' ) ) |
591 return true; |
746 return true; |
592 |
747 |
593 return ! $hasher->CheckPassword( $post->post_password, $hash ); |
748 return ! $hasher->CheckPassword( $post->post_password, $hash ); |
594 } |
749 } |
595 |
750 |
596 /** |
751 // |
597 * Page Template Functions for usage in Themes |
752 // Page Template Functions for usage in Themes |
598 * |
753 // |
599 * @package WordPress |
|
600 * @subpackage Template |
|
601 */ |
|
602 |
754 |
603 /** |
755 /** |
604 * The formatted output of a list of pages. |
756 * The formatted output of a list of pages. |
605 * |
757 * |
606 * Displays page links for paginated posts (i.e. includes the <!--nextpage-->. |
758 * Displays page links for paginated posts (i.e. includes the <!--nextpage-->. |
607 * Quicktag one or more times). This tag must be within The Loop. |
759 * Quicktag one or more times). This tag must be within The Loop. |
608 * |
760 * |
609 * The defaults for overwriting are: |
|
610 * 'before' - Default is '<p> Pages:' (string). The html or text to prepend to |
|
611 * each bookmarks. |
|
612 * 'after' - Default is '</p>' (string). The html or text to append to each |
|
613 * bookmarks. |
|
614 * 'link_before' - Default is '' (string). The html or text to prepend to each |
|
615 * Pages link inside the <a> tag. Also prepended to the current item, which |
|
616 * is not linked. |
|
617 * 'link_after' - Default is '' (string). The html or text to append to each |
|
618 * Pages link inside the <a> tag. Also appended to the current item, which |
|
619 * is not linked. |
|
620 * 'next_or_number' - Default is 'number' (string). Indicates whether page |
|
621 * numbers should be used. Valid values are number and next. |
|
622 * 'separator' - Default is ' ' (string). Text used between pagination links. |
|
623 * 'nextpagelink' - Default is 'Next Page' (string). Text for link to next page. |
|
624 * of the bookmark. |
|
625 * 'previouspagelink' - Default is 'Previous Page' (string). Text for link to |
|
626 * previous page, if available. |
|
627 * 'pagelink' - Default is '%' (String).Format string for page numbers. The % in |
|
628 * the parameter string will be replaced with the page number, so Page % |
|
629 * generates "Page 1", "Page 2", etc. Defaults to %, just the page number. |
|
630 * 'echo' - Default is 1 (integer). When not 0, this triggers the HTML to be |
|
631 * echoed and then returned. |
|
632 * |
|
633 * @since 1.2.0 |
761 * @since 1.2.0 |
634 * |
762 * |
635 * @param string|array $args Optional. Overwrite the defaults. |
763 * @param string|array $args { |
|
764 * Optional. Array or string of default arguments. |
|
765 * |
|
766 * @type string $before HTML or text to prepend to each link. Default is `<p> Pages:`. |
|
767 * @type string $after HTML or text to append to each link. Default is `</p>`. |
|
768 * @type string $link_before HTML or text to prepend to each link, inside the `<a>` tag. |
|
769 * Also prepended to the current item, which is not linked. Default empty. |
|
770 * @type string $link_after HTML or text to append to each Pages link inside the `<a>` tag. |
|
771 * Also appended to the current item, which is not linked. Default empty. |
|
772 * @type string $next_or_number Indicates whether page numbers should be used. Valid values are number |
|
773 * and next. Default is 'number'. |
|
774 * @type string $separator Text between pagination links. Default is ' '. |
|
775 * @type string $nextpagelink Link text for the next page link, if available. Default is 'Next Page'. |
|
776 * @type string $previouspagelink Link text for the previous page link, if available. Default is 'Previous Page'. |
|
777 * @type string $pagelink Format string for page numbers. The % in the parameter string will be |
|
778 * replaced with the page number, so 'Page %' generates "Page 1", "Page 2", etc. |
|
779 * Defaults to '%', just the page number. |
|
780 * @type int|bool $echo Whether to echo or not. Accepts 1|true or 0|false. Default 1|true. |
|
781 * } |
636 * @return string Formatted output in HTML. |
782 * @return string Formatted output in HTML. |
637 */ |
783 */ |
638 function wp_link_pages( $args = '' ) { |
784 function wp_link_pages( $args = '' ) { |
639 $defaults = array( |
785 $defaults = array( |
640 'before' => '<p>' . __( 'Pages:' ), |
786 'before' => '<p>' . __( 'Pages:' ), |
647 'previouspagelink' => __( 'Previous page' ), |
793 'previouspagelink' => __( 'Previous page' ), |
648 'pagelink' => '%', |
794 'pagelink' => '%', |
649 'echo' => 1 |
795 'echo' => 1 |
650 ); |
796 ); |
651 |
797 |
652 $r = wp_parse_args( $args, $defaults ); |
798 $params = wp_parse_args( $args, $defaults ); |
653 $r = apply_filters( 'wp_link_pages_args', $r ); |
799 |
654 extract( $r, EXTR_SKIP ); |
800 /** |
|
801 * Filter the arguments used in retrieving page links for paginated posts. |
|
802 * |
|
803 * @since 3.0.0 |
|
804 * |
|
805 * @param array $params An array of arguments for page links for paginated posts. |
|
806 */ |
|
807 $r = apply_filters( 'wp_link_pages_args', $params ); |
655 |
808 |
656 global $page, $numpages, $multipage, $more; |
809 global $page, $numpages, $multipage, $more; |
657 |
810 |
658 $output = ''; |
811 $output = ''; |
659 if ( $multipage ) { |
812 if ( $multipage ) { |
660 if ( 'number' == $next_or_number ) { |
813 if ( 'number' == $r['next_or_number'] ) { |
661 $output .= $before; |
814 $output .= $r['before']; |
662 for ( $i = 1; $i <= $numpages; $i++ ) { |
815 for ( $i = 1; $i <= $numpages; $i++ ) { |
663 $link = $link_before . str_replace( '%', $i, $pagelink ) . $link_after; |
816 $link = $r['link_before'] . str_replace( '%', $i, $r['pagelink'] ) . $r['link_after']; |
664 if ( $i != $page || ! $more && 1 == $page ) |
817 if ( $i != $page || ! $more && 1 == $page ) { |
665 $link = _wp_link_page( $i ) . $link . '</a>'; |
818 $link = _wp_link_page( $i ) . $link . '</a>'; |
|
819 } |
|
820 /** |
|
821 * Filter the HTML output of individual page number links. |
|
822 * |
|
823 * @since 3.6.0 |
|
824 * |
|
825 * @param string $link The page number HTML output. |
|
826 * @param int $i Page number for paginated posts' page links. |
|
827 */ |
666 $link = apply_filters( 'wp_link_pages_link', $link, $i ); |
828 $link = apply_filters( 'wp_link_pages_link', $link, $i ); |
667 $output .= $separator . $link; |
829 |
|
830 // Use the custom links separator beginning with the second link. |
|
831 $output .= ( 1 === $i ) ? ' ' : $r['separator']; |
|
832 $output .= $link; |
668 } |
833 } |
669 $output .= $after; |
834 $output .= $r['after']; |
670 } elseif ( $more ) { |
835 } elseif ( $more ) { |
671 $output .= $before; |
836 $output .= $r['before']; |
672 $i = $page - 1; |
837 $prev = $page - 1; |
673 if ( $i ) { |
838 if ( $prev ) { |
674 $link = _wp_link_page( $i ) . $link_before . $previouspagelink . $link_after . '</a>'; |
839 $link = _wp_link_page( $prev ) . $r['link_before'] . $r['previouspagelink'] . $r['link_after'] . '</a>'; |
675 $link = apply_filters( 'wp_link_pages_link', $link, $i ); |
840 |
676 $output .= $separator . $link; |
841 /** This filter is documented in wp-includes/post-template.php */ |
|
842 $output .= apply_filters( 'wp_link_pages_link', $link, $prev ); |
677 } |
843 } |
678 $i = $page + 1; |
844 $next = $page + 1; |
679 if ( $i <= $numpages ) { |
845 if ( $next <= $numpages ) { |
680 $link = _wp_link_page( $i ) . $link_before . $nextpagelink . $link_after . '</a>'; |
846 if ( $prev ) { |
681 $link = apply_filters( 'wp_link_pages_link', $link, $i ); |
847 $output .= $r['separator']; |
682 $output .= $separator . $link; |
848 } |
|
849 $link = _wp_link_page( $next ) . $r['link_before'] . $r['nextpagelink'] . $r['link_after'] . '</a>'; |
|
850 |
|
851 /** This filter is documented in wp-includes/post-template.php */ |
|
852 $output .= apply_filters( 'wp_link_pages_link', $link, $next ); |
683 } |
853 } |
684 $output .= $after; |
854 $output .= $r['after']; |
685 } |
855 } |
686 } |
856 } |
687 |
857 |
688 $output = apply_filters( 'wp_link_pages', $output, $args ); |
858 /** |
689 |
859 * Filter the HTML output of page links for paginated posts. |
690 if ( $echo ) |
860 * |
691 echo $output; |
861 * @since 3.6.0 |
692 |
862 * |
693 return $output; |
863 * @param string $output HTML output of paginated posts' page links. |
|
864 * @param array $args An array of arguments. |
|
865 */ |
|
866 $html = apply_filters( 'wp_link_pages', $output, $args ); |
|
867 |
|
868 if ( $r['echo'] ) { |
|
869 echo $html; |
|
870 } |
|
871 return $html; |
694 } |
872 } |
695 |
873 |
696 /** |
874 /** |
697 * Helper function for wp_link_pages(). |
875 * Helper function for wp_link_pages(). |
698 * |
876 * |
771 |
971 |
772 /** |
972 /** |
773 * Retrieve or display list of pages as a dropdown (select list). |
973 * Retrieve or display list of pages as a dropdown (select list). |
774 * |
974 * |
775 * @since 2.1.0 |
975 * @since 2.1.0 |
776 * |
976 * @since 4.2.0 The `$value_field` argument was added. |
777 * @param array|string $args Optional. Override default arguments. |
977 * |
|
978 * @param array|string $args { |
|
979 * Optional. Array or string of arguments to generate a pages drop-down element. |
|
980 * |
|
981 * @type int $depth Maximum depth. Default 0. |
|
982 * @type int $child_of Page ID to retrieve child pages of. Default 0. |
|
983 * @type int|string $selected Value of the option that should be selected. Default 0. |
|
984 * @type bool|int $echo Whether to echo or return the generated markup. Accepts 0, 1, |
|
985 * or their bool equivalents. Default 1. |
|
986 * @type string $name Value for the 'name' attribute of the select element. |
|
987 * Default 'page_id'. |
|
988 * @type string $id Value for the 'id' attribute of the select element. |
|
989 * Defaults to the value of `$name`. |
|
990 * @type string $show_option_none Text to display for showing no pages. Default empty (does not display). |
|
991 * @type string $show_option_no_change Text to display for "no change" option. Default empty (does not display). |
|
992 * @type string $option_none_value Value to use when no page is selected. Default empty. |
|
993 * @type string $value_field Post field used to populate the 'value' attribute of the option |
|
994 * elements. Accepts any valid post field. Default 'ID'. |
|
995 * } |
778 * @return string HTML content, if not displaying. |
996 * @return string HTML content, if not displaying. |
779 */ |
997 */ |
780 function wp_dropdown_pages($args = '') { |
998 function wp_dropdown_pages( $args = '' ) { |
781 $defaults = array( |
999 $defaults = array( |
782 'depth' => 0, 'child_of' => 0, |
1000 'depth' => 0, 'child_of' => 0, |
783 'selected' => 0, 'echo' => 1, |
1001 'selected' => 0, 'echo' => 1, |
784 'name' => 'page_id', 'id' => '', |
1002 'name' => 'page_id', 'id' => '', |
785 'show_option_none' => '', 'show_option_no_change' => '', |
1003 'show_option_none' => '', 'show_option_no_change' => '', |
786 'option_none_value' => '' |
1004 'option_none_value' => '', |
|
1005 'value_field' => 'ID', |
787 ); |
1006 ); |
788 |
1007 |
789 $r = wp_parse_args( $args, $defaults ); |
1008 $r = wp_parse_args( $args, $defaults ); |
790 extract( $r, EXTR_SKIP ); |
1009 |
791 |
1010 $pages = get_pages( $r ); |
792 $pages = get_pages($r); |
|
793 $output = ''; |
1011 $output = ''; |
794 // Back-compat with old system where both id and name were based on $name argument |
1012 // Back-compat with old system where both id and name were based on $name argument |
795 if ( empty($id) ) |
1013 if ( empty( $r['id'] ) ) { |
796 $id = $name; |
1014 $r['id'] = $r['name']; |
797 |
1015 } |
798 if ( ! empty($pages) ) { |
1016 |
799 $output = "<select name='" . esc_attr( $name ) . "' id='" . esc_attr( $id ) . "'>\n"; |
1017 if ( ! empty( $pages ) ) { |
800 if ( $show_option_no_change ) |
1018 $output = "<select name='" . esc_attr( $r['name'] ) . "' id='" . esc_attr( $r['id'] ) . "'>\n"; |
801 $output .= "\t<option value=\"-1\">$show_option_no_change</option>"; |
1019 if ( $r['show_option_no_change'] ) { |
802 if ( $show_option_none ) |
1020 $output .= "\t<option value=\"-1\">" . $r['show_option_no_change'] . "</option>\n"; |
803 $output .= "\t<option value=\"" . esc_attr($option_none_value) . "\">$show_option_none</option>\n"; |
1021 } |
804 $output .= walk_page_dropdown_tree($pages, $depth, $r); |
1022 if ( $r['show_option_none'] ) { |
|
1023 $output .= "\t<option value=\"" . esc_attr( $r['option_none_value'] ) . '">' . $r['show_option_none'] . "</option>\n"; |
|
1024 } |
|
1025 $output .= walk_page_dropdown_tree( $pages, $r['depth'], $r ); |
805 $output .= "</select>\n"; |
1026 $output .= "</select>\n"; |
806 } |
1027 } |
807 |
1028 |
808 $output = apply_filters('wp_dropdown_pages', $output); |
1029 /** |
809 |
1030 * Filter the HTML output of a list of pages as a drop down. |
810 if ( $echo ) |
1031 * |
811 echo $output; |
1032 * @since 2.1.0 |
812 |
1033 * |
813 return $output; |
1034 * @param string $output HTML output for drop down list of pages. |
|
1035 */ |
|
1036 $html = apply_filters( 'wp_dropdown_pages', $output ); |
|
1037 |
|
1038 if ( $r['echo'] ) { |
|
1039 echo $html; |
|
1040 } |
|
1041 return $html; |
814 } |
1042 } |
815 |
1043 |
816 /** |
1044 /** |
817 * Retrieve or display list of pages in list (li) format. |
1045 * Retrieve or display list of pages in list (li) format. |
818 * |
1046 * |
819 * @since 1.5.0 |
1047 * @since 1.5.0 |
820 * |
1048 * |
821 * @param array|string $args Optional. Override default arguments. |
1049 * @see get_pages() |
822 * @return string HTML content, if not displaying. |
1050 * |
823 */ |
1051 * @param array|string $args { |
824 function wp_list_pages($args = '') { |
1052 * Array or string of arguments. Optional. |
|
1053 * |
|
1054 * @type int $child_of Display only the sub-pages of a single page by ID. Default 0 (all pages). |
|
1055 * @type string $authors Comma-separated list of author IDs. Default empty (all authors). |
|
1056 * @type string $date_format PHP date format to use for the listed pages. Relies on the 'show_date' parameter. |
|
1057 * Default is the value of 'date_format' option. |
|
1058 * @type int $depth Number of levels in the hierarchy of pages to include in the generated list. |
|
1059 * Accepts -1 (any depth), 0 (all pages), 1 (top-level pages only), and n (pages to |
|
1060 * the given n depth). Default 0. |
|
1061 * @type bool $echo Whether or not to echo the list of pages. Default true. |
|
1062 * @type string $exclude Comma-separated list of page IDs to exclude. Default empty. |
|
1063 * @type array $include Comma-separated list of page IDs to include. Default empty. |
|
1064 * @type string $link_after Text or HTML to follow the page link label. Default null. |
|
1065 * @type string $link_before Text or HTML to precede the page link label. Default null. |
|
1066 * @type string $post_type Post type to query for. Default 'page'. |
|
1067 * @type string $post_status Comma-separated list of post statuses to include. Default 'publish'. |
|
1068 * @type string $show_date Whether to display the page publish or modified date for each page. Accepts |
|
1069 * 'modified' or any other value. An empty value hides the date. Default empty. |
|
1070 * @type string $sort_column Comma-separated list of column names to sort the pages by. Accepts 'post_author', |
|
1071 * 'post_date', 'post_title', 'post_name', 'post_modified', 'post_modified_gmt', |
|
1072 * 'menu_order', 'post_parent', 'ID', 'rand', or 'comment_count'. Default 'post_title'. |
|
1073 * @type string $title_li List heading. Passing a null or empty value will result in no heading, and the list |
|
1074 * will not be wrapped with unordered list `<ul>` tags. Default 'Pages'. |
|
1075 * @type Walker $walker Walker instance to use for listing pages. Default empty (Walker_Page). |
|
1076 * } |
|
1077 * @return string HTML list of pages. |
|
1078 */ |
|
1079 function wp_list_pages( $args = '' ) { |
825 $defaults = array( |
1080 $defaults = array( |
826 'depth' => 0, 'show_date' => '', |
1081 'depth' => 0, 'show_date' => '', |
827 'date_format' => get_option('date_format'), |
1082 'date_format' => get_option( 'date_format' ), |
828 'child_of' => 0, 'exclude' => '', |
1083 'child_of' => 0, 'exclude' => '', |
829 'title_li' => __('Pages'), 'echo' => 1, |
1084 'title_li' => __( 'Pages' ), 'echo' => 1, |
830 'authors' => '', 'sort_column' => 'menu_order, post_title', |
1085 'authors' => '', 'sort_column' => 'menu_order, post_title', |
831 'link_before' => '', 'link_after' => '', 'walker' => '', |
1086 'link_before' => '', 'link_after' => '', 'walker' => '', |
832 ); |
1087 ); |
833 |
1088 |
834 $r = wp_parse_args( $args, $defaults ); |
1089 $r = wp_parse_args( $args, $defaults ); |
835 extract( $r, EXTR_SKIP ); |
|
836 |
1090 |
837 $output = ''; |
1091 $output = ''; |
838 $current_page = 0; |
1092 $current_page = 0; |
839 |
1093 |
840 // sanitize, mostly to keep spaces out |
1094 // sanitize, mostly to keep spaces out |
841 $r['exclude'] = preg_replace('/[^0-9,]/', '', $r['exclude']); |
1095 $r['exclude'] = preg_replace( '/[^0-9,]/', '', $r['exclude'] ); |
842 |
1096 |
843 // Allow plugins to filter an array of excluded pages (but don't put a nullstring into the array) |
1097 // Allow plugins to filter an array of excluded pages (but don't put a nullstring into the array) |
844 $exclude_array = ( $r['exclude'] ) ? explode(',', $r['exclude']) : array(); |
1098 $exclude_array = ( $r['exclude'] ) ? explode( ',', $r['exclude'] ) : array(); |
845 $r['exclude'] = implode( ',', apply_filters('wp_list_pages_excludes', $exclude_array) ); |
1099 |
|
1100 /** |
|
1101 * Filter the array of pages to exclude from the pages list. |
|
1102 * |
|
1103 * @since 2.1.0 |
|
1104 * |
|
1105 * @param array $exclude_array An array of page IDs to exclude. |
|
1106 */ |
|
1107 $r['exclude'] = implode( ',', apply_filters( 'wp_list_pages_excludes', $exclude_array ) ); |
846 |
1108 |
847 // Query pages. |
1109 // Query pages. |
848 $r['hierarchical'] = 0; |
1110 $r['hierarchical'] = 0; |
849 $pages = get_pages($r); |
1111 $pages = get_pages( $r ); |
850 |
1112 |
851 if ( !empty($pages) ) { |
1113 if ( ! empty( $pages ) ) { |
852 if ( $r['title_li'] ) |
1114 if ( $r['title_li'] ) { |
853 $output .= '<li class="pagenav">' . $r['title_li'] . '<ul>'; |
1115 $output .= '<li class="pagenav">' . $r['title_li'] . '<ul>'; |
854 |
1116 } |
855 global $wp_query; |
1117 global $wp_query; |
856 if ( is_page() || is_attachment() || $wp_query->is_posts_page ) |
1118 if ( is_page() || is_attachment() || $wp_query->is_posts_page ) { |
857 $current_page = $wp_query->get_queried_object_id(); |
1119 $current_page = get_queried_object_id(); |
858 $output .= walk_page_tree($pages, $r['depth'], $current_page, $r); |
1120 } elseif ( is_singular() ) { |
859 |
1121 $queried_object = get_queried_object(); |
860 if ( $r['title_li'] ) |
1122 if ( is_post_type_hierarchical( $queried_object->post_type ) ) { |
|
1123 $current_page = $queried_object->ID; |
|
1124 } |
|
1125 } |
|
1126 |
|
1127 $output .= walk_page_tree( $pages, $r['depth'], $current_page, $r ); |
|
1128 |
|
1129 if ( $r['title_li'] ) { |
861 $output .= '</ul></li>'; |
1130 $output .= '</ul></li>'; |
862 } |
1131 } |
863 |
1132 } |
864 $output = apply_filters('wp_list_pages', $output, $r); |
1133 |
865 |
1134 /** |
866 if ( $r['echo'] ) |
1135 * Filter the HTML output of the pages to list. |
867 echo $output; |
1136 * |
868 else |
1137 * @since 1.5.1 |
869 return $output; |
1138 * |
|
1139 * @see wp_list_pages() |
|
1140 * |
|
1141 * @param string $output HTML output of the pages list. |
|
1142 * @param array $r An array of page-listing arguments. |
|
1143 */ |
|
1144 $html = apply_filters( 'wp_list_pages', $output, $r ); |
|
1145 |
|
1146 if ( $r['echo'] ) { |
|
1147 echo $html; |
|
1148 } else { |
|
1149 return $html; |
|
1150 } |
870 } |
1151 } |
871 |
1152 |
872 /** |
1153 /** |
873 * Display or retrieve list of pages with optional home link. |
1154 * Display or retrieve list of pages with optional home link. |
874 * |
1155 * |
875 * The arguments are listed below and part of the arguments are for {@link |
1156 * The arguments are listed below and part of the arguments are for {@link |
876 * wp_list_pages()} function. Check that function for more info on those |
1157 * wp_list_pages()} function. Check that function for more info on those |
877 * arguments. |
1158 * arguments. |
878 * |
1159 * |
879 * <ul> |
|
880 * <li><strong>sort_column</strong> - How to sort the list of pages. Defaults |
|
881 * to 'menu_order, post_title'. Use column for posts table.</li> |
|
882 * <li><strong>menu_class</strong> - Class to use for the div ID which contains |
|
883 * the page list. Defaults to 'menu'.</li> |
|
884 * <li><strong>echo</strong> - Whether to echo list or return it. Defaults to |
|
885 * echo.</li> |
|
886 * <li><strong>link_before</strong> - Text before show_home argument text.</li> |
|
887 * <li><strong>link_after</strong> - Text after show_home argument text.</li> |
|
888 * <li><strong>show_home</strong> - If you set this argument, then it will |
|
889 * display the link to the home page. The show_home argument really just needs |
|
890 * to be set to the value of the text of the link.</li> |
|
891 * </ul> |
|
892 * |
|
893 * @since 2.7.0 |
1160 * @since 2.7.0 |
894 * |
1161 * |
895 * @param array|string $args |
1162 * @param array|string $args { |
|
1163 * Optional. Arguments to generate a page menu. See wp_list_pages() for additional arguments. |
|
1164 * |
|
1165 * @type string $sort_column How to short the list of pages. Accepts post column names. |
|
1166 * Default 'menu_order, post_title'. |
|
1167 * @type string $menu_class Class to use for the div ID containing the page list. Default 'menu'. |
|
1168 * @type bool $echo Whether to echo the list or return it. Accepts true (echo) or false (return). |
|
1169 * Default true. |
|
1170 * @type string $link_before The HTML or text to prepend to $show_home text. Default empty. |
|
1171 * @type string $link_after The HTML or text to append to $show_home text. Default empty. |
|
1172 * @type int|bool|string $show_home Whether to display the link to the home page. Can just enter the text |
|
1173 * you'd like shown for the home link. 1|true defaults to 'Home'. |
|
1174 * } |
896 * @return string html menu |
1175 * @return string html menu |
897 */ |
1176 */ |
898 function wp_page_menu( $args = array() ) { |
1177 function wp_page_menu( $args = array() ) { |
899 $defaults = array('sort_column' => 'menu_order, post_title', 'menu_class' => 'menu', 'echo' => true, 'link_before' => '', 'link_after' => ''); |
1178 $defaults = array('sort_column' => 'menu_order, post_title', 'menu_class' => 'menu', 'echo' => true, 'link_before' => '', 'link_after' => ''); |
900 $args = wp_parse_args( $args, $defaults ); |
1179 $args = wp_parse_args( $args, $defaults ); |
|
1180 |
|
1181 /** |
|
1182 * Filter the arguments used to generate a page-based menu. |
|
1183 * |
|
1184 * @since 2.7.0 |
|
1185 * |
|
1186 * @see wp_page_menu() |
|
1187 * |
|
1188 * @param array $args An array of page menu arguments. |
|
1189 */ |
901 $args = apply_filters( 'wp_page_menu_args', $args ); |
1190 $args = apply_filters( 'wp_page_menu_args', $args ); |
902 |
1191 |
903 $menu = ''; |
1192 $menu = ''; |
904 |
1193 |
905 $list_args = $args; |
1194 $list_args = $args; |
1040 * @param object $page Page data object. |
1339 * @param object $page Page data object. |
1041 * @param int $depth Depth of page. Used for padding. |
1340 * @param int $depth Depth of page. Used for padding. |
1042 * @param int $current_page Page ID. |
1341 * @param int $current_page Page ID. |
1043 * @param array $args |
1342 * @param array $args |
1044 */ |
1343 */ |
1045 function start_el( &$output, $page, $depth = 0, $args = array(), $current_page = 0 ) { |
1344 public function start_el( &$output, $page, $depth = 0, $args = array(), $current_page = 0 ) { |
1046 if ( $depth ) |
1345 if ( $depth ) { |
1047 $indent = str_repeat("\t", $depth); |
1346 $indent = str_repeat( "\t", $depth ); |
1048 else |
1347 } else { |
1049 $indent = ''; |
1348 $indent = ''; |
1050 |
1349 } |
1051 extract($args, EXTR_SKIP); |
1350 |
1052 $css_class = array('page_item', 'page-item-'.$page->ID); |
1351 $css_class = array( 'page_item', 'page-item-' . $page->ID ); |
1053 |
1352 |
1054 if( isset( $args['pages_with_children'][ $page->ID ] ) ) |
1353 if ( isset( $args['pages_with_children'][ $page->ID ] ) ) { |
1055 $css_class[] = 'page_item_has_children'; |
1354 $css_class[] = 'page_item_has_children'; |
1056 |
1355 } |
1057 if ( !empty($current_page) ) { |
1356 |
|
1357 if ( ! empty( $current_page ) ) { |
1058 $_current_page = get_post( $current_page ); |
1358 $_current_page = get_post( $current_page ); |
1059 if ( in_array( $page->ID, $_current_page->ancestors ) ) |
1359 if ( $_current_page && in_array( $page->ID, $_current_page->ancestors ) ) { |
1060 $css_class[] = 'current_page_ancestor'; |
1360 $css_class[] = 'current_page_ancestor'; |
1061 if ( $page->ID == $current_page ) |
1361 } |
|
1362 if ( $page->ID == $current_page ) { |
1062 $css_class[] = 'current_page_item'; |
1363 $css_class[] = 'current_page_item'; |
1063 elseif ( $_current_page && $page->ID == $_current_page->post_parent ) |
1364 } elseif ( $_current_page && $page->ID == $_current_page->post_parent ) { |
1064 $css_class[] = 'current_page_parent'; |
1365 $css_class[] = 'current_page_parent'; |
|
1366 } |
1065 } elseif ( $page->ID == get_option('page_for_posts') ) { |
1367 } elseif ( $page->ID == get_option('page_for_posts') ) { |
1066 $css_class[] = 'current_page_parent'; |
1368 $css_class[] = 'current_page_parent'; |
1067 } |
1369 } |
1068 |
1370 |
1069 $css_class = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page ) ); |
1371 /** |
1070 |
1372 * Filter the list of CSS classes to include with each page item in the list. |
1071 if ( '' === $page->post_title ) |
1373 * |
|
1374 * @since 2.8.0 |
|
1375 * |
|
1376 * @see wp_list_pages() |
|
1377 * |
|
1378 * @param array $css_class An array of CSS classes to be applied |
|
1379 * to each list item. |
|
1380 * @param WP_Post $page Page data object. |
|
1381 * @param int $depth Depth of page, used for padding. |
|
1382 * @param array $args An array of arguments. |
|
1383 * @param int $current_page ID of the current page. |
|
1384 */ |
|
1385 $css_classes = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page ) ); |
|
1386 |
|
1387 if ( '' === $page->post_title ) { |
1072 $page->post_title = sprintf( __( '#%d (no title)' ), $page->ID ); |
1388 $page->post_title = sprintf( __( '#%d (no title)' ), $page->ID ); |
|
1389 } |
|
1390 |
|
1391 $args['link_before'] = empty( $args['link_before'] ) ? '' : $args['link_before']; |
|
1392 $args['link_after'] = empty( $args['link_after'] ) ? '' : $args['link_after']; |
1073 |
1393 |
1074 /** This filter is documented in wp-includes/post-template.php */ |
1394 /** This filter is documented in wp-includes/post-template.php */ |
1075 $output .= $indent . '<li class="' . $css_class . '"><a href="' . get_permalink($page->ID) . '">' . $link_before . apply_filters( 'the_title', $page->post_title, $page->ID ) . $link_after . '</a>'; |
1395 $output .= $indent . sprintf( |
1076 |
1396 '<li class="%s"><a href="%s">%s%s%s</a>', |
1077 if ( !empty($show_date) ) { |
1397 $css_classes, |
1078 if ( 'modified' == $show_date ) |
1398 get_permalink( $page->ID ), |
|
1399 $args['link_before'], |
|
1400 apply_filters( 'the_title', $page->post_title, $page->ID ), |
|
1401 $args['link_after'] |
|
1402 ); |
|
1403 |
|
1404 if ( ! empty( $args['show_date'] ) ) { |
|
1405 if ( 'modified' == $args['show_date'] ) { |
1079 $time = $page->post_modified; |
1406 $time = $page->post_modified; |
1080 else |
1407 } else { |
1081 $time = $page->post_date; |
1408 $time = $page->post_date; |
1082 |
1409 } |
1083 $output .= " " . mysql2date($date_format, $time); |
1410 |
|
1411 $date_format = empty( $args['date_format'] ) ? '' : $args['date_format']; |
|
1412 $output .= " " . mysql2date( $date_format, $time ); |
1084 } |
1413 } |
1085 } |
1414 } |
1086 |
1415 |
1087 /** |
1416 /** |
1088 * @see Walker::end_el() |
1417 * @see Walker::end_el() |
1091 * @param string $output Passed by reference. Used to append additional content. |
1420 * @param string $output Passed by reference. Used to append additional content. |
1092 * @param object $page Page data object. Not used. |
1421 * @param object $page Page data object. Not used. |
1093 * @param int $depth Depth of page. Not Used. |
1422 * @param int $depth Depth of page. Not Used. |
1094 * @param array $args |
1423 * @param array $args |
1095 */ |
1424 */ |
1096 function end_el( &$output, $page, $depth = 0, $args = array() ) { |
1425 public function end_el( &$output, $page, $depth = 0, $args = array() ) { |
1097 $output .= "</li>\n"; |
1426 $output .= "</li>\n"; |
1098 } |
1427 } |
1099 |
1428 |
1100 } |
1429 } |
1101 |
1430 |
1102 /** |
1431 /** |
1103 * Create HTML dropdown list of pages. |
1432 * Create HTML dropdown list of pages. |
1104 * |
1433 * |
1105 * @package WordPress |
|
1106 * @since 2.1.0 |
1434 * @since 2.1.0 |
1107 * @uses Walker |
1435 * @uses Walker |
1108 */ |
1436 */ |
1109 class Walker_PageDropdown extends Walker { |
1437 class Walker_PageDropdown extends Walker { |
1110 /** |
1438 /** |
1111 * @see Walker::$tree_type |
1439 * @see Walker::$tree_type |
1112 * @since 2.1.0 |
1440 * @since 2.1.0 |
1113 * @var string |
1441 * @var string |
1114 */ |
1442 */ |
1115 var $tree_type = 'page'; |
1443 public $tree_type = 'page'; |
1116 |
1444 |
1117 /** |
1445 /** |
1118 * @see Walker::$db_fields |
1446 * @see Walker::$db_fields |
1119 * @since 2.1.0 |
1447 * @since 2.1.0 |
1120 * @todo Decouple this |
1448 * @todo Decouple this |
1121 * @var array |
1449 * @var array |
1122 */ |
1450 */ |
1123 var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID'); |
1451 public $db_fields = array ('parent' => 'post_parent', 'id' => 'ID'); |
1124 |
1452 |
1125 /** |
1453 /** |
1126 * @see Walker::start_el() |
1454 * @see Walker::start_el() |
1127 * @since 2.1.0 |
1455 * @since 2.1.0 |
1128 * |
1456 * |
1129 * @param string $output Passed by reference. Used to append additional content. |
1457 * @param string $output Passed by reference. Used to append additional content. |
1130 * @param object $page Page data object. |
1458 * @param object $page Page data object. |
1131 * @param int $depth Depth of page in reference to parent pages. Used for padding. |
1459 * @param int $depth Depth of page in reference to parent pages. Used for padding. |
1132 * @param array $args Uses 'selected' argument for selected page to set selected HTML attribute for option element. |
1460 * @param array $args Uses 'selected' argument for selected page to set selected HTML attribute for option |
|
1461 * element. Uses 'value_field' argument to fill "value" attribute. See {@see wp_dropdown_pages()}. |
1133 * @param int $id |
1462 * @param int $id |
1134 */ |
1463 */ |
1135 function start_el( &$output, $page, $depth = 0, $args = array(), $id = 0 ) { |
1464 public function start_el( &$output, $page, $depth = 0, $args = array(), $id = 0 ) { |
1136 $pad = str_repeat(' ', $depth * 3); |
1465 $pad = str_repeat(' ', $depth * 3); |
1137 |
1466 |
1138 $output .= "\t<option class=\"level-$depth\" value=\"$page->ID\""; |
1467 if ( ! isset( $args['value_field'] ) || ! isset( $page->{$args['value_field']} ) ) { |
|
1468 $args['value_field'] = 'ID'; |
|
1469 } |
|
1470 |
|
1471 $output .= "\t<option class=\"level-$depth\" value=\"" . esc_attr( $page->{$args['value_field']} ) . "\""; |
1139 if ( $page->ID == $args['selected'] ) |
1472 if ( $page->ID == $args['selected'] ) |
1140 $output .= ' selected="selected"'; |
1473 $output .= ' selected="selected"'; |
1141 $output .= '>'; |
1474 $output .= '>'; |
1142 $title = apply_filters( 'list_pages', $page->post_title, $page ); |
1475 |
|
1476 $title = $page->post_title; |
|
1477 if ( '' === $title ) { |
|
1478 $title = sprintf( __( '#%d (no title)' ), $page->ID ); |
|
1479 } |
|
1480 |
|
1481 /** |
|
1482 * Filter the page title when creating an HTML drop-down list of pages. |
|
1483 * |
|
1484 * @since 3.1.0 |
|
1485 * |
|
1486 * @param string $title Page title. |
|
1487 * @param object $page Page data object. |
|
1488 */ |
|
1489 $title = apply_filters( 'list_pages', $title, $page ); |
1143 $output .= $pad . esc_html( $title ); |
1490 $output .= $pad . esc_html( $title ); |
1144 $output .= "</option>\n"; |
1491 $output .= "</option>\n"; |
1145 } |
1492 } |
1146 } |
1493 } |
1147 |
1494 |
1171 |
1518 |
1172 /** |
1519 /** |
1173 * Retrieve an attachment page link using an image or icon, if possible. |
1520 * Retrieve an attachment page link using an image or icon, if possible. |
1174 * |
1521 * |
1175 * @since 2.5.0 |
1522 * @since 2.5.0 |
1176 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function. |
1523 * |
1177 * |
1524 * @param int|WP_Post $id Optional. Post ID or post object. |
1178 * @param int $id Optional. Post ID. |
1525 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string. |
1179 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string. |
1526 * @param bool $permalink Optional, default is false. Whether to add permalink to image. |
1180 * @param bool $permalink Optional, default is false. Whether to add permalink to image. |
1527 * @param bool $icon Optional, default is false. Whether to include icon. |
1181 * @param bool $icon Optional, default is false. Whether to include icon. |
1528 * @param string|bool $text Optional, default is false. If string, then will be link text. |
1182 * @param string|bool $text Optional, default is false. If string, then will be link text. |
1529 * @param array|string $attr Optional. Array or string of attributes. |
1183 * @return string HTML content. |
1530 * @return string HTML content. |
1184 */ |
1531 */ |
1185 function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false ) { |
1532 function wp_get_attachment_link( $id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false, $attr = '' ) { |
1186 $id = intval( $id ); |
1533 $id = intval( $id ); |
1187 $_post = get_post( $id ); |
1534 $_post = get_post( $id ); |
1188 |
1535 |
1189 if ( empty( $_post ) || ( 'attachment' != $_post->post_type ) || ! $url = wp_get_attachment_url( $_post->ID ) ) |
1536 if ( empty( $_post ) || ( 'attachment' != $_post->post_type ) || ! $url = wp_get_attachment_url( $_post->ID ) ) |
1190 return __( 'Missing Attachment' ); |
1537 return __( 'Missing Attachment' ); |
1191 |
1538 |
1192 if ( $permalink ) |
1539 if ( $permalink ) |
1193 $url = get_attachment_link( $_post->ID ); |
1540 $url = get_attachment_link( $_post->ID ); |
1194 |
1541 |
1195 $post_title = esc_attr( $_post->post_title ); |
1542 if ( $text ) { |
1196 |
|
1197 if ( $text ) |
|
1198 $link_text = $text; |
1543 $link_text = $text; |
1199 elseif ( $size && 'none' != $size ) |
1544 } elseif ( $size && 'none' != $size ) { |
1200 $link_text = wp_get_attachment_image( $id, $size, $icon ); |
1545 $link_text = wp_get_attachment_image( $id, $size, $icon, $attr ); |
1201 else |
1546 } else { |
1202 $link_text = ''; |
1547 $link_text = ''; |
|
1548 } |
1203 |
1549 |
1204 if ( trim( $link_text ) == '' ) |
1550 if ( trim( $link_text ) == '' ) |
1205 $link_text = $_post->post_title; |
1551 $link_text = $_post->post_title; |
1206 |
1552 |
|
1553 /** |
|
1554 * Filter a retrieved attachment page link. |
|
1555 * |
|
1556 * @since 2.7.0 |
|
1557 * |
|
1558 * @param string $link_html The page link HTML output. |
|
1559 * @param int $id Post ID. |
|
1560 * @param string $size Image size. Default 'thumbnail'. |
|
1561 * @param bool $permalink Whether to add permalink to image. Default false. |
|
1562 * @param bool $icon Whether to include an icon. Default false. |
|
1563 * @param string|bool $text If string, will be link text. Default false. |
|
1564 */ |
1207 return apply_filters( 'wp_get_attachment_link', "<a href='$url'>$link_text</a>", $id, $size, $permalink, $icon, $text ); |
1565 return apply_filters( 'wp_get_attachment_link', "<a href='$url'>$link_text</a>", $id, $size, $permalink, $icon, $text ); |
1208 } |
1566 } |
1209 |
1567 |
1210 /** |
1568 /** |
1211 * Wrap attachment in <<p>> element before content. |
1569 * Wrap attachment in paragraph tag before content. |
1212 * |
1570 * |
1213 * @since 2.0.0 |
1571 * @since 2.0.0 |
1214 * @uses apply_filters() Calls 'prepend_attachment' hook on HTML content. |
|
1215 * |
1572 * |
1216 * @param string $content |
1573 * @param string $content |
1217 * @return string |
1574 * @return string |
1218 */ |
1575 */ |
1219 function prepend_attachment($content) { |
1576 function prepend_attachment($content) { |
1220 $post = get_post(); |
1577 $post = get_post(); |
1221 |
1578 |
1222 if ( empty($post->post_type) || $post->post_type != 'attachment' ) |
1579 if ( empty($post->post_type) || $post->post_type != 'attachment' ) |
1223 return $content; |
1580 return $content; |
1224 |
1581 |
1225 $p = '<p class="attachment">'; |
1582 if ( wp_attachment_is( 'video', $post ) ) { |
1226 // show the medium sized image representation of the attachment if available, and link to the raw file |
1583 $meta = wp_get_attachment_metadata( get_the_ID() ); |
1227 $p .= wp_get_attachment_link(0, 'medium', false); |
1584 $atts = array( 'src' => wp_get_attachment_url() ); |
1228 $p .= '</p>'; |
1585 if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) { |
1229 $p = apply_filters('prepend_attachment', $p); |
1586 $atts['width'] = (int) $meta['width']; |
|
1587 $atts['height'] = (int) $meta['height']; |
|
1588 } |
|
1589 if ( has_post_thumbnail() ) { |
|
1590 $atts['poster'] = wp_get_attachment_url( get_post_thumbnail_id() ); |
|
1591 } |
|
1592 $p = wp_video_shortcode( $atts ); |
|
1593 } elseif ( wp_attachment_is( 'audio', $post ) ) { |
|
1594 $p = wp_audio_shortcode( array( 'src' => wp_get_attachment_url() ) ); |
|
1595 } else { |
|
1596 $p = '<p class="attachment">'; |
|
1597 // show the medium sized image representation of the attachment if available, and link to the raw file |
|
1598 $p .= wp_get_attachment_link(0, 'medium', false); |
|
1599 $p .= '</p>'; |
|
1600 } |
|
1601 |
|
1602 /** |
|
1603 * Filter the attachment markup to be prepended to the post content. |
|
1604 * |
|
1605 * @since 2.0.0 |
|
1606 * |
|
1607 * @see prepend_attachment() |
|
1608 * |
|
1609 * @param string $p The attachment HTML output. |
|
1610 */ |
|
1611 $p = apply_filters( 'prepend_attachment', $p ); |
1230 |
1612 |
1231 return "$p\n$content"; |
1613 return "$p\n$content"; |
1232 } |
1614 } |
1233 |
1615 |
1234 // |
1616 // |