3 * WordPress Post Template Functions.
5 * Gets content for the current post in the loop.
12 * Display the ID of the current item in the WordPress Loop.
21 * Retrieve the ID of the current item in the WordPress Loop.
28 function get_the_ID() {
34 * Display or retrieve the current post title with optional content.
38 * @param string $before Optional. Content to prepend to the title.
39 * @param string $after Optional. Content to append to the title.
40 * @param bool $echo Optional, default to true.Whether to display or return.
41 * @return null|string Null on no title. String if $echo parameter is false.
43 function the_title($before = '', $after = '', $echo = true) {
44 $title = get_the_title();
46 if ( strlen($title) == 0 )
49 $title = $before . $title . $after;
58 * Sanitize the current title when retrieving or displaying.
60 * Works like {@link the_title()}, except the parameters can be in a string or
61 * an array. See the function for what can be override in the $args parameter.
63 * The title before it is displayed will have the tags stripped and {@link
64 * esc_attr()} before it is passed to the user or displayed. The default
65 * as with {@link the_title()}, is to display the title.
69 * @param string|array $args Optional. Override the defaults.
70 * @return string|null Null on failure or display. String when echo is false.
72 function the_title_attribute( $args = '' ) {
73 $title = get_the_title();
75 if ( strlen($title) == 0 )
78 $defaults = array('before' => '', 'after' => '', 'echo' => true);
79 $r = wp_parse_args($args, $defaults);
80 extract( $r, EXTR_SKIP );
83 $title = $before . $title . $after;
84 $title = esc_attr(strip_tags($title));
93 * Retrieve post title.
95 * If the post is protected and the visitor is not an admin, then "Protected"
96 * will be displayed before the post title. If the post is private, then
97 * "Private" will be located before the post title.
101 * @param int $id Optional. Post ID.
104 function get_the_title( $id = 0 ) {
105 $post = &get_post($id);
107 $title = isset($post->post_title) ? $post->post_title : '';
108 $id = isset($post->ID) ? $post->ID : (int) $id;
111 if ( !empty($post->post_password) ) {
112 $protected_title_format = apply_filters('protected_title_format', __('Protected: %s'));
113 $title = sprintf($protected_title_format, $title);
114 } else if ( isset($post->post_status) && 'private' == $post->post_status ) {
115 $private_title_format = apply_filters('private_title_format', __('Private: %s'));
116 $title = sprintf($private_title_format, $title);
119 return apply_filters( 'the_title', $title, $id );
123 * Display the Post Global Unique Identifier (guid).
125 * The guid will appear to be a link, but should not be used as an link to the
126 * post. The reason you should not use it as a link, is because of moving the
127 * blog across domains.
129 * Url is escaped to make it xml safe
133 * @param int $id Optional. Post ID.
135 function the_guid( $id = 0 ) {
136 echo esc_url( get_the_guid( $id ) );
140 * Retrieve the Post Global Unique Identifier (guid).
142 * The guid will appear to be a link, but should not be used as an link to the
143 * post. The reason you should not use it as a link, is because of moving the
144 * blog across domains.
148 * @param int $id Optional. Post ID.
151 function get_the_guid( $id = 0 ) {
152 $post = &get_post($id);
154 return apply_filters('get_the_guid', $post->guid);
158 * Display the post content.
162 * @param string $more_link_text Optional. Content for when there is more text.
163 * @param string $stripteaser Optional. Teaser content before the more text.
165 function the_content($more_link_text = null, $stripteaser = 0) {
166 $content = get_the_content($more_link_text, $stripteaser);
167 $content = apply_filters('the_content', $content);
168 $content = str_replace(']]>', ']]>', $content);
173 * Retrieve the post content.
177 * @param string $more_link_text Optional. Content for when there is more text.
178 * @param string $stripteaser Optional. Teaser content before the more text.
181 function get_the_content($more_link_text = null, $stripteaser = 0) {
182 global $post, $more, $page, $pages, $multipage, $preview;
184 if ( null === $more_link_text )
185 $more_link_text = __( '(more...)' );
190 // If post password required and it doesn't match the cookie.
191 if ( post_password_required($post) ) {
192 $output = get_the_password_form();
196 if ( $page > count($pages) ) // if the requested page doesn't exist
197 $page = count($pages); // give them the highest numbered page that DOES exist
199 $content = $pages[$page-1];
200 if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
201 $content = explode($matches[0], $content, 2);
202 if ( !empty($matches[1]) && !empty($more_link_text) )
203 $more_link_text = strip_tags(wp_kses_no_null(trim($matches[1])));
207 $content = array($content);
209 if ( (false !== strpos($post->post_content, '<!--noteaser-->') && ((!$multipage) || ($page==1))) )
211 $teaser = $content[0];
212 if ( ($more) && ($stripteaser) && ($hasTeaser) )
215 if ( count($content) > 1 ) {
217 $output .= '<span id="more-' . $post->ID . '"></span>' . $content[1];
219 if ( ! empty($more_link_text) )
220 $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-{$post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text );
221 $output = force_balance_tags($output);
225 if ( $preview ) // preview fix for javascript bug with foreign languages
226 $output = preg_replace_callback('/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output);
232 * Preview fix for javascript bug with foreign languages
236 * @param array $match Match array from preg_replace_callback
239 function _convert_urlencoded_to_entities( $match ) {
240 return '&#' . base_convert( $match[1], 16, 10 ) . ';';
244 * Display the post excerpt.
247 * @uses apply_filters() Calls 'the_excerpt' hook on post excerpt.
249 function the_excerpt() {
250 echo apply_filters('the_excerpt', get_the_excerpt());
254 * Retrieve the post excerpt.
258 * @param mixed $deprecated Not used.
261 function get_the_excerpt( $deprecated = '' ) {
262 if ( !empty( $deprecated ) )
263 _deprecated_argument( __FUNCTION__, '2.3' );
266 $output = $post->post_excerpt;
267 if ( post_password_required($post) ) {
268 $output = __('There is no excerpt because this is a protected post.');
272 return apply_filters('get_the_excerpt', $output);
276 * Whether post has excerpt.
280 * @param int $id Optional. Post ID.
283 function has_excerpt( $id = 0 ) {
284 $post = &get_post( $id );
285 return ( !empty( $post->post_excerpt ) );
289 * Display the classes for the post div.
293 * @param string|array $class One or more classes to add to the class list.
294 * @param int $post_id An optional post ID.
296 function post_class( $class = '', $post_id = null ) {
297 // Separates classes with a single space, collates classes for post DIV
298 echo 'class="' . join( ' ', get_post_class( $class, $post_id ) ) . '"';
302 * Retrieve the classes for the post div as an array.
304 * The class names are add are many. If the post is a sticky, then the 'sticky'
305 * class name. The class 'hentry' is always added to each post. For each
306 * category, the class will be added with 'category-' with category slug is
307 * added. The tags are the same way as the categories with 'tag-' before the tag
308 * slug. All classes are passed through the filter, 'post_class' with the list
309 * of classes, followed by $class parameter value, with the post ID as the last
314 * @param string|array $class One or more classes to add to the class list.
315 * @param int $post_id An optional post ID.
316 * @return array Array of classes.
318 function get_post_class( $class = '', $post_id = null ) {
319 $post = get_post($post_id);
326 $classes[] = 'post-' . $post->ID;
327 $classes[] = $post->post_type;
328 $classes[] = 'type-' . $post->post_type;
329 $classes[] = 'status-' . $post->post_status;
332 $post_format = get_post_format( $post->ID );
334 if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
335 if ( $post_format && !is_wp_error($post_format) )
336 $classes[] = 'format-' . sanitize_html_class( $post_format );
338 $classes[] = 'format-standard';
341 // post requires password
342 if ( post_password_required($post->ID) )
343 $classes[] = 'post-password-required';
345 // sticky for Sticky Posts
346 if ( is_sticky($post->ID) && is_home() && !is_paged() )
347 $classes[] = 'sticky';
349 // hentry for hAtom compliance
350 $classes[] = 'hentry';
353 if ( is_object_in_taxonomy( $post->post_type, 'category' ) ) {
354 foreach ( (array) get_the_category($post->ID) as $cat ) {
355 if ( empty($cat->slug ) )
357 $classes[] = 'category-' . sanitize_html_class($cat->slug, $cat->term_id);
362 if ( is_object_in_taxonomy( $post->post_type, 'post_tag' ) ) {
363 foreach ( (array) get_the_tags($post->ID) as $tag ) {
364 if ( empty($tag->slug ) )
366 $classes[] = 'tag-' . sanitize_html_class($tag->slug, $tag->term_id);
370 if ( !empty($class) ) {
371 if ( !is_array( $class ) )
372 $class = preg_split('#\s+#', $class);
373 $classes = array_merge($classes, $class);
376 $classes = array_map('esc_attr', $classes);
378 return apply_filters('post_class', $classes, $class, $post->ID);
382 * Display the classes for the body element.
386 * @param string|array $class One or more classes to add to the class list.
388 function body_class( $class = '' ) {
389 // Separates classes with a single space, collates classes for body element
390 echo 'class="' . join( ' ', get_body_class( $class ) ) . '"';
394 * Retrieve the classes for the body element as an array.
398 * @param string|array $class One or more classes to add to the class list.
399 * @return array Array of classes.
401 function get_body_class( $class = '' ) {
402 global $wp_query, $wpdb;
409 if ( is_front_page() )
414 $classes[] = 'archive';
418 $classes[] = 'search';
420 $classes[] = 'paged';
421 if ( is_attachment() )
422 $classes[] = 'attachment';
424 $classes[] = 'error404';
427 $post_id = $wp_query->get_queried_object_id();
428 $post = $wp_query->get_queried_object();
430 $classes[] = 'single';
431 $classes[] = 'single-' . sanitize_html_class($post->post_type, $post_id);
432 $classes[] = 'postid-' . $post_id;
435 $post_format = get_post_format( $post->ID );
437 if ( $post_format && !is_wp_error($post_format) )
438 $classes[] = 'single-format-' . sanitize_html_class( $post_format );
440 $classes[] = 'single-format-standard';
442 if ( is_attachment() ) {
443 $mime_type = get_post_mime_type($post_id);
444 $mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' );
445 $classes[] = 'attachmentid-' . $post_id;
446 $classes[] = 'attachment-' . str_replace( $mime_prefix, '', $mime_type );
448 } elseif ( is_archive() ) {
449 if ( is_post_type_archive() ) {
450 $classes[] = 'post-type-archive';
451 $classes[] = 'post-type-archive-' . sanitize_html_class( get_query_var( 'post_type' ) );
452 } else if ( is_author() ) {
453 $author = $wp_query->get_queried_object();
454 $classes[] = 'author';
455 $classes[] = 'author-' . sanitize_html_class( $author->user_nicename , $author->ID );
456 $classes[] = 'author-' . $author->ID;
457 } elseif ( is_category() ) {
458 $cat = $wp_query->get_queried_object();
459 $classes[] = 'category';
460 $classes[] = 'category-' . sanitize_html_class( $cat->slug, $cat->term_id );
461 $classes[] = 'category-' . $cat->term_id;
462 } elseif ( is_tag() ) {
463 $tags = $wp_query->get_queried_object();
465 $classes[] = 'tag-' . sanitize_html_class( $tags->slug, $tags->term_id );
466 $classes[] = 'tag-' . $tags->term_id;
467 } elseif ( is_tax() ) {
468 $term = $wp_query->get_queried_object();
469 $classes[] = 'tax-' . sanitize_html_class( $term->taxonomy );
470 $classes[] = 'term-' . sanitize_html_class( $term->slug, $term->term_id );
471 $classes[] = 'term-' . $term->term_id;
473 } elseif ( is_page() ) {
476 $page_id = $wp_query->get_queried_object_id();
478 $post = get_page($page_id);
480 $classes[] = 'page-id-' . $page_id;
482 if ( $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status = 'publish' LIMIT 1", $page_id) ) )
483 $classes[] = 'page-parent';
485 if ( $post->post_parent ) {
486 $classes[] = 'page-child';
487 $classes[] = 'parent-pageid-' . $post->post_parent;
489 if ( is_page_template() ) {
490 $classes[] = 'page-template';
491 $classes[] = 'page-template-' . sanitize_html_class( str_replace( '.', '-', get_post_meta( $page_id, '_wp_page_template', true ) ), '' );
493 } elseif ( is_search() ) {
494 if ( !empty( $wp_query->posts ) )
495 $classes[] = 'search-results';
497 $classes[] = 'search-no-results';
500 if ( is_user_logged_in() )
501 $classes[] = 'logged-in';
503 if ( is_admin_bar_showing() )
504 $classes[] = 'admin-bar';
506 $page = $wp_query->get( 'page' );
508 if ( !$page || $page < 2)
509 $page = $wp_query->get( 'paged' );
511 if ( $page && $page > 1 ) {
512 $classes[] = 'paged-' . $page;
515 $classes[] = 'single-paged-' . $page;
517 $classes[] = 'page-paged-' . $page;
518 elseif ( is_category() )
519 $classes[] = 'category-paged-' . $page;
521 $classes[] = 'tag-paged-' . $page;
523 $classes[] = 'date-paged-' . $page;
524 elseif ( is_author() )
525 $classes[] = 'author-paged-' . $page;
526 elseif ( is_search() )
527 $classes[] = 'search-paged-' . $page;
528 elseif ( is_post_type_archive() )
529 $classes[] = 'post-type-paged-' . $page;
532 if ( !empty( $class ) ) {
533 if ( !is_array( $class ) )
534 $class = preg_split( '#\s+#', $class );
535 $classes = array_merge( $classes, $class );
538 $classes = array_map( 'esc_attr', $classes );
540 return apply_filters( 'body_class', $classes, $class );
544 * Whether post requires password and correct password has been provided.
548 * @param int|object $post An optional post. Global $post used if not provided.
549 * @return bool false if a password is not required or the correct password cookie is present, true otherwise.
551 function post_password_required( $post = null ) {
552 $post = get_post($post);
554 if ( empty($post->post_password) )
557 if ( !isset($_COOKIE['wp-postpass_' . COOKIEHASH]) )
560 if ( $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password )
567 * Display "sticky" CSS class, if a post is sticky.
571 * @param int $post_id An optional post ID.
573 function sticky_class( $post_id = null ) {
574 if ( !is_sticky($post_id) )
581 * Page Template Functions for usage in Themes
584 * @subpackage Template
588 * The formatted output of a list of pages.
590 * Displays page links for paginated posts (i.e. includes the <!--nextpage-->.
591 * Quicktag one or more times). This tag must be within The Loop.
593 * The defaults for overwriting are:
594 * 'next_or_number' - Default is 'number' (string). Indicates whether page
595 * numbers should be used. Valid values are number and next.
596 * 'nextpagelink' - Default is 'Next Page' (string). Text for link to next page.
598 * 'previouspagelink' - Default is 'Previous Page' (string). Text for link to
599 * previous page, if available.
600 * 'pagelink' - Default is '%' (String).Format string for page numbers. The % in
601 * the parameter string will be replaced with the page number, so Page %
602 * generates "Page 1", "Page 2", etc. Defaults to %, just the page number.
603 * 'before' - Default is '<p> Pages:' (string). The html or text to prepend to
605 * 'after' - Default is '</p>' (string). The html or text to append to each
607 * 'link_before' - Default is '' (string). The html or text to prepend to each
608 * Pages link inside the <a> tag. Also prepended to the current item, which
610 * 'link_after' - Default is '' (string). The html or text to append to each
611 * Pages link inside the <a> tag. Also appended to the current item, which
617 * @param string|array $args Optional. Overwrite the defaults.
618 * @return string Formatted output in HTML.
620 function wp_link_pages($args = '') {
622 'before' => '<p>' . __('Pages:'), 'after' => '</p>',
623 'link_before' => '', 'link_after' => '',
624 'next_or_number' => 'number', 'nextpagelink' => __('Next page'),
625 'previouspagelink' => __('Previous page'), 'pagelink' => '%',
629 $r = wp_parse_args( $args, $defaults );
630 $r = apply_filters( 'wp_link_pages_args', $r );
631 extract( $r, EXTR_SKIP );
633 global $page, $numpages, $multipage, $more, $pagenow;
637 if ( 'number' == $next_or_number ) {
639 for ( $i = 1; $i < ($numpages+1); $i = $i + 1 ) {
640 $j = str_replace('%',$i,$pagelink);
642 if ( ($i != $page) || ((!$more) && ($page==1)) ) {
643 $output .= _wp_link_page($i);
645 $output .= $link_before . $j . $link_after;
646 if ( ($i != $page) || ((!$more) && ($page==1)) )
655 $output .= _wp_link_page($i);
656 $output .= $link_before. $previouspagelink . $link_after . '</a>';
659 if ( $i <= $numpages && $more ) {
660 $output .= _wp_link_page($i);
661 $output .= $link_before. $nextpagelink . $link_after . '</a>';
675 * Helper function for wp_link_pages().
680 * @param int $i Page number.
681 * @return string Link.
683 function _wp_link_page( $i ) {
684 global $post, $wp_rewrite;
687 $url = get_permalink();
689 if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )
690 $url = add_query_arg( 'page', $i, get_permalink() );
691 elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID )
692 $url = trailingslashit(get_permalink()) . user_trailingslashit("$wp_rewrite->pagination_base/" . $i, 'single_paged');
694 $url = trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged');
697 return '<a href="' . esc_url( $url ) . '">';
701 // Post-meta: Custom per-post fields.
705 * Retrieve post custom meta data field.
709 * @param string $key Meta data key name.
710 * @return bool|string|array Array of values or single value, if only one element exists. False will be returned if key does not exist.
712 function post_custom( $key = '' ) {
713 $custom = get_post_custom();
715 if ( !isset( $custom[$key] ) )
717 elseif ( 1 == count($custom[$key]) )
718 return $custom[$key][0];
720 return $custom[$key];
724 * Display list of post custom fields.
726 * @internal This will probably change at some point...
728 * @uses apply_filters() Calls 'the_meta_key' on list item HTML content, with key and value as separate parameters.
730 function the_meta() {
731 if ( $keys = get_post_custom_keys() ) {
732 echo "<ul class='post-meta'>\n";
733 foreach ( (array) $keys as $key ) {
735 if ( '_' == $keyt[0] )
737 $values = array_map('trim', get_post_custom_values($key));
738 $value = implode($values,', ');
739 echo apply_filters('the_meta_key', "<li><span class='post-meta-key'>$key:</span> $value</li>\n", $key, $value);
750 * Retrieve or display list of pages as a dropdown (select list).
754 * @param array|string $args Optional. Override default arguments.
755 * @return string HTML content, if not displaying.
757 function wp_dropdown_pages($args = '') {
759 'depth' => 0, 'child_of' => 0,
760 'selected' => 0, 'echo' => 1,
761 'name' => 'page_id', 'id' => '',
762 'show_option_none' => '', 'show_option_no_change' => '',
763 'option_none_value' => ''
766 $r = wp_parse_args( $args, $defaults );
767 extract( $r, EXTR_SKIP );
769 $pages = get_pages($r);
771 $name = esc_attr($name);
772 // Back-compat with old system where both id and name were based on $name argument
776 if ( ! empty($pages) ) {
777 $output = "<select name=\"$name\" id=\"$id\">\n";
778 if ( $show_option_no_change )
779 $output .= "\t<option value=\"-1\">$show_option_no_change</option>";
780 if ( $show_option_none )
781 $output .= "\t<option value=\"" . esc_attr($option_none_value) . "\">$show_option_none</option>\n";
782 $output .= walk_page_dropdown_tree($pages, $depth, $r);
783 $output .= "</select>\n";
786 $output = apply_filters('wp_dropdown_pages', $output);
795 * Retrieve or display list of pages in list (li) format.
799 * @param array|string $args Optional. Override default arguments.
800 * @return string HTML content, if not displaying.
802 function wp_list_pages($args = '') {
804 'depth' => 0, 'show_date' => '',
805 'date_format' => get_option('date_format'),
806 'child_of' => 0, 'exclude' => '',
807 'title_li' => __('Pages'), 'echo' => 1,
808 'authors' => '', 'sort_column' => 'menu_order, post_title',
809 'link_before' => '', 'link_after' => '', 'walker' => '',
812 $r = wp_parse_args( $args, $defaults );
813 extract( $r, EXTR_SKIP );
818 // sanitize, mostly to keep spaces out
819 $r['exclude'] = preg_replace('/[^0-9,]/', '', $r['exclude']);
821 // Allow plugins to filter an array of excluded pages (but don't put a nullstring into the array)
822 $exclude_array = ( $r['exclude'] ) ? explode(',', $r['exclude']) : array();
823 $r['exclude'] = implode( ',', apply_filters('wp_list_pages_excludes', $exclude_array) );
826 $r['hierarchical'] = 0;
827 $pages = get_pages($r);
829 if ( !empty($pages) ) {
830 if ( $r['title_li'] )
831 $output .= '<li class="pagenav">' . $r['title_li'] . '<ul>';
834 if ( is_page() || is_attachment() || $wp_query->is_posts_page )
835 $current_page = $wp_query->get_queried_object_id();
836 $output .= walk_page_tree($pages, $r['depth'], $current_page, $r);
838 if ( $r['title_li'] )
839 $output .= '</ul></li>';
842 $output = apply_filters('wp_list_pages', $output, $r);
851 * Display or retrieve list of pages with optional home link.
853 * The arguments are listed below and part of the arguments are for {@link
854 * wp_list_pages()} function. Check that function for more info on those
858 * <li><strong>sort_column</strong> - How to sort the list of pages. Defaults
859 * to page title. Use column for posts table.</li>
860 * <li><strong>menu_class</strong> - Class to use for the div ID which contains
861 * the page list. Defaults to 'menu'.</li>
862 * <li><strong>echo</strong> - Whether to echo list or return it. Defaults to
864 * <li><strong>link_before</strong> - Text before show_home argument text.</li>
865 * <li><strong>link_after</strong> - Text after show_home argument text.</li>
866 * <li><strong>show_home</strong> - If you set this argument, then it will
867 * display the link to the home page. The show_home argument really just needs
868 * to be set to the value of the text of the link.</li>
873 * @param array|string $args
875 function wp_page_menu( $args = array() ) {
876 $defaults = array('sort_column' => 'menu_order, post_title', 'menu_class' => 'menu', 'echo' => true, 'link_before' => '', 'link_after' => '');
877 $args = wp_parse_args( $args, $defaults );
878 $args = apply_filters( 'wp_page_menu_args', $args );
884 // Show Home in the menu
885 if ( ! empty($args['show_home']) ) {
886 if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] )
889 $text = $args['show_home'];
891 if ( is_front_page() && !is_paged() )
892 $class = 'class="current_page_item"';
893 $menu .= '<li ' . $class . '><a href="' . home_url( '/' ) . '" title="' . esc_attr($text) . '">' . $args['link_before'] . $text . $args['link_after'] . '</a></li>';
894 // If the front page is a page, add it to the exclude list
895 if (get_option('show_on_front') == 'page') {
896 if ( !empty( $list_args['exclude'] ) ) {
897 $list_args['exclude'] .= ',';
899 $list_args['exclude'] = '';
901 $list_args['exclude'] .= get_option('page_on_front');
905 $list_args['echo'] = false;
906 $list_args['title_li'] = '';
907 $menu .= str_replace( array( "\r", "\n", "\t" ), '', wp_list_pages($list_args) );
910 $menu = '<ul>' . $menu . '</ul>';
912 $menu = '<div class="' . esc_attr($args['menu_class']) . '">' . $menu . "</div>\n";
913 $menu = apply_filters( 'wp_page_menu', $menu, $args );
925 * Retrieve HTML list content for page list.
927 * @uses Walker_Page to create HTML list content.
929 * @see Walker_Page::walk() for parameters and return description.
931 function walk_page_tree($pages, $depth, $current_page, $r) {
932 if ( empty($r['walker']) )
933 $walker = new Walker_Page;
935 $walker = $r['walker'];
937 $args = array($pages, $depth, $r, $current_page);
938 return call_user_func_array(array(&$walker, 'walk'), $args);
942 * Retrieve HTML dropdown (select) content for page list.
944 * @uses Walker_PageDropdown to create HTML dropdown content.
946 * @see Walker_PageDropdown::walk() for parameters and return description.
948 function walk_page_dropdown_tree() {
949 $args = func_get_args();
950 if ( empty($args[2]['walker']) ) // the user's options are the third parameter
951 $walker = new Walker_PageDropdown;
953 $walker = $args[2]['walker'];
955 return call_user_func_array(array(&$walker, 'walk'), $args);
959 * Create HTML list of pages.
965 class Walker_Page extends Walker {
967 * @see Walker::$tree_type
971 var $tree_type = 'page';
974 * @see Walker::$db_fields
976 * @todo Decouple this.
979 var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');
982 * @see Walker::start_lvl()
985 * @param string $output Passed by reference. Used to append additional content.
986 * @param int $depth Depth of page. Used for padding.
988 function start_lvl(&$output, $depth) {
989 $indent = str_repeat("\t", $depth);
990 $output .= "\n$indent<ul class='children'>\n";
994 * @see Walker::end_lvl()
997 * @param string $output Passed by reference. Used to append additional content.
998 * @param int $depth Depth of page. Used for padding.
1000 function end_lvl(&$output, $depth) {
1001 $indent = str_repeat("\t", $depth);
1002 $output .= "$indent</ul>\n";
1006 * @see Walker::start_el()
1009 * @param string $output Passed by reference. Used to append additional content.
1010 * @param object $page Page data object.
1011 * @param int $depth Depth of page. Used for padding.
1012 * @param int $current_page Page ID.
1013 * @param array $args
1015 function start_el(&$output, $page, $depth, $args, $current_page) {
1017 $indent = str_repeat("\t", $depth);
1021 extract($args, EXTR_SKIP);
1022 $css_class = array('page_item', 'page-item-'.$page->ID);
1023 if ( !empty($current_page) ) {
1024 $_current_page = get_page( $current_page );
1025 _get_post_ancestors($_current_page);
1026 if ( isset($_current_page->ancestors) && in_array($page->ID, (array) $_current_page->ancestors) )
1027 $css_class[] = 'current_page_ancestor';
1028 if ( $page->ID == $current_page )
1029 $css_class[] = 'current_page_item';
1030 elseif ( $_current_page && $page->ID == $_current_page->post_parent )
1031 $css_class[] = 'current_page_parent';
1032 } elseif ( $page->ID == get_option('page_for_posts') ) {
1033 $css_class[] = 'current_page_parent';
1036 $css_class = implode(' ', apply_filters('page_css_class', $css_class, $page));
1038 $output .= $indent . '<li class="' . $css_class . '"><a href="' . get_permalink($page->ID) . '" title="' . esc_attr( wp_strip_all_tags( apply_filters( 'the_title', $page->post_title, $page->ID ) ) ) . '">' . $link_before . apply_filters( 'the_title', $page->post_title, $page->ID ) . $link_after . '</a>';
1040 if ( !empty($show_date) ) {
1041 if ( 'modified' == $show_date )
1042 $time = $page->post_modified;
1044 $time = $page->post_date;
1046 $output .= " " . mysql2date($date_format, $time);
1051 * @see Walker::end_el()
1054 * @param string $output Passed by reference. Used to append additional content.
1055 * @param object $page Page data object. Not used.
1056 * @param int $depth Depth of page. Not Used.
1058 function end_el(&$output, $page, $depth) {
1059 $output .= "</li>\n";
1065 * Create HTML dropdown list of pages.
1067 * @package WordPress
1071 class Walker_PageDropdown extends Walker {
1073 * @see Walker::$tree_type
1077 var $tree_type = 'page';
1080 * @see Walker::$db_fields
1082 * @todo Decouple this
1085 var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');
1088 * @see Walker::start_el()
1091 * @param string $output Passed by reference. Used to append additional content.
1092 * @param object $page Page data object.
1093 * @param int $depth Depth of page in reference to parent pages. Used for padding.
1094 * @param array $args Uses 'selected' argument for selected page to set selected HTML attribute for option element.
1096 function start_el(&$output, $page, $depth, $args) {
1097 $pad = str_repeat(' ', $depth * 3);
1099 $output .= "\t<option class=\"level-$depth\" value=\"$page->ID\"";
1100 if ( $page->ID == $args['selected'] )
1101 $output .= ' selected="selected"';
1103 $title = esc_html($page->post_title);
1104 $title = apply_filters( 'list_pages', $page->post_title );
1105 $output .= "$pad$title";
1106 $output .= "</option>\n";
1115 * Display an attachment page link using an image or icon.
1119 * @param int $id Optional. Post ID.
1120 * @param bool $fullsize Optional, default is false. Whether to use full size.
1121 * @param bool $deprecated Deprecated. Not used.
1122 * @param bool $permalink Optional, default is false. Whether to include permalink.
1124 function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $permalink = false ) {
1125 if ( !empty( $deprecated ) )
1126 _deprecated_argument( __FUNCTION__, '2.5' );
1129 echo wp_get_attachment_link($id, 'full', $permalink);
1131 echo wp_get_attachment_link($id, 'thumbnail', $permalink);
1135 * Retrieve an attachment page link using an image or icon, if possible.
1138 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
1140 * @param int $id Optional. Post ID.
1141 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
1142 * @param bool $permalink Optional, default is false. Whether to add permalink to image.
1143 * @param bool $icon Optional, default is false. Whether to include icon.
1144 * @param string $text Optional, default is false. If string, then will be link text.
1145 * @return string HTML content.
1147 function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false) {
1149 $_post = & get_post( $id );
1151 if ( ('attachment' != $_post->post_type) || !$url = wp_get_attachment_url($_post->ID) )
1152 return __('Missing Attachment');
1155 $url = get_attachment_link($_post->ID);
1157 $post_title = esc_attr($_post->post_title);
1160 $link_text = esc_attr($text);
1161 } elseif ( ( is_int($size) && $size != 0 ) or ( is_string($size) && $size != 'none' ) or $size != false ) {
1162 $link_text = wp_get_attachment_image($id, $size, $icon);
1167 if( trim($link_text) == '' )
1168 $link_text = $_post->post_title;
1170 return apply_filters( 'wp_get_attachment_link', "<a href='$url' title='$post_title'>$link_text</a>", $id, $size, $permalink, $icon, $text );
1174 * Wrap attachment in <<p>> element before content.
1177 * @uses apply_filters() Calls 'prepend_attachment' hook on HTML content.
1179 * @param string $content
1182 function prepend_attachment($content) {
1185 if ( empty($post->post_type) || $post->post_type != 'attachment' )
1188 $p = '<p class="attachment">';
1189 // show the medium sized image representation of the attachment if available, and link to the raw file
1190 $p .= wp_get_attachment_link(0, 'medium', false);
1192 $p = apply_filters('prepend_attachment', $p);
1194 return "$p\n$content";
1202 * Retrieve protected post password form content.
1205 * @uses apply_filters() Calls 'the_password_form' filter on output.
1207 * @return string HTML content for password form for password protected post.
1209 function get_the_password_form() {
1211 $label = 'pwbox-'.(empty($post->ID) ? rand() : $post->ID);
1212 $output = '<form action="' . get_option('siteurl') . '/wp-pass.php" method="post">
1213 <p>' . __("This post is password protected. To view it please enter your password below:") . '</p>
1214 <p><label for="' . $label . '">' . __("Password:") . ' <input name="post_password" id="' . $label . '" type="password" size="20" /></label> <input type="submit" name="Submit" value="' . esc_attr__("Submit") . '" /></p>
1217 return apply_filters('the_password_form', $output);
1221 * Whether currently in a page template.
1223 * This template tag allows you to determine if you are in a page template.
1224 * You can optionally provide a template name and then the check will be
1225 * specific to that template.
1230 * @param string $template The specific template name if specific matching is required.
1231 * @return bool False on failure, true if success.
1233 function is_page_template($template = '') {
1240 $page = $wp_query->get_queried_object();
1241 $custom_fields = get_post_custom_values('_wp_page_template',$page->ID);
1242 $page_template = $custom_fields[0];
1244 // We have no argument passed so just see if a page_template has been specified
1245 if ( empty( $template ) ) {
1246 if (!empty( $page_template ) ) {
1249 } elseif ( $template == $page_template) {
1257 * Retrieve formatted date timestamp of a revision (linked to that revisions's page).
1259 * @package WordPress
1260 * @subpackage Post_Revisions
1265 * @param int|object $revision Revision ID or revision object.
1266 * @param bool $link Optional, default is true. Link to revisions's page?
1267 * @return string i18n formatted datetimestamp or localized 'Current Revision'.
1269 function wp_post_revision_title( $revision, $link = true ) {
1270 if ( !$revision = get_post( $revision ) )
1273 if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) )
1276 /* translators: revision date format, see http://php.net/date */
1277 $datef = _x( 'j F, Y @ G:i', 'revision date format');
1278 /* translators: 1: date */
1279 $autosavef = __( '%1$s [Autosave]' );
1280 /* translators: 1: date */
1281 $currentf = __( '%1$s [Current Revision]' );
1283 $date = date_i18n( $datef, strtotime( $revision->post_modified ) );
1284 if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) )
1285 $date = "<a href='$link'>$date</a>";
1287 if ( !wp_is_post_revision( $revision ) )
1288 $date = sprintf( $currentf, $date );
1289 elseif ( wp_is_post_autosave( $revision ) )
1290 $date = sprintf( $autosavef, $date );
1296 * Display list of a post's revisions.
1298 * Can output either a UL with edit links or a TABLE with diff interface, and
1299 * restore action links.
1301 * Second argument controls parameters:
1302 * (bool) parent : include the parent (the "Current Revision") in the list.
1303 * (string) format : 'list' or 'form-table'. 'list' outputs UL, 'form-table'
1304 * outputs TABLE with UI.
1305 * (int) right : what revision is currently being viewed - used in
1306 * form-table format.
1307 * (int) left : what revision is currently being diffed against right -
1308 * used in form-table format.
1310 * @package WordPress
1311 * @subpackage Post_Revisions
1314 * @uses wp_get_post_revisions()
1315 * @uses wp_post_revision_title()
1316 * @uses get_edit_post_link()
1317 * @uses get_the_author_meta()
1319 * @todo split into two functions (list, form-table) ?
1321 * @param int|object $post_id Post ID or post object.
1322 * @param string|array $args See description {@link wp_parse_args()}.
1325 function wp_list_post_revisions( $post_id = 0, $args = null ) {
1326 if ( !$post = get_post( $post_id ) )
1329 $defaults = array( 'parent' => false, 'right' => false, 'left' => false, 'format' => 'list', 'type' => 'all' );
1330 extract( wp_parse_args( $args, $defaults ), EXTR_SKIP );
1334 if ( !$autosave = wp_get_post_autosave( $post->ID ) )
1336 $revisions = array( $autosave );
1338 case 'revision' : // just revisions - remove autosave later
1341 if ( !$revisions = wp_get_post_revisions( $post->ID ) )
1346 /* translators: post revision: 1: when, 2: author name */
1347 $titlef = _x( '%1$s by %2$s', 'post revision' );
1350 array_unshift( $revisions, $post );
1354 $can_edit_post = current_user_can( 'edit_post', $post->ID );
1355 foreach ( $revisions as $revision ) {
1356 if ( !current_user_can( 'read_post', $revision->ID ) )
1358 if ( 'revision' === $type && wp_is_post_autosave( $revision ) )
1361 $date = wp_post_revision_title( $revision );
1362 $name = get_the_author_meta( 'display_name', $revision->post_author );
1364 if ( 'form-table' == $format ) {
1366 $left_checked = $left == $revision->ID ? ' checked="checked"' : '';
1368 $left_checked = $right_checked ? ' checked="checked"' : ''; // [sic] (the next one)
1369 $right_checked = $right == $revision->ID ? ' checked="checked"' : '';
1371 $class = $class ? '' : " class='alternate'";
1373 if ( $post->ID != $revision->ID && $can_edit_post )
1374 $actions = '<a href="' . wp_nonce_url( add_query_arg( array( 'revision' => $revision->ID, 'action' => 'restore' ) ), "restore-post_$post->ID|$revision->ID" ) . '">' . __( 'Restore' ) . '</a>';
1378 $rows .= "<tr$class>\n";
1379 $rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='left' value='$revision->ID'$left_checked /></th>\n";
1380 $rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='right' value='$revision->ID'$right_checked /></th>\n";
1381 $rows .= "\t<td>$date</td>\n";
1382 $rows .= "\t<td>$name</td>\n";
1383 $rows .= "\t<td class='action-links'>$actions</td>\n";
1386 $title = sprintf( $titlef, $date, $name );
1387 $rows .= "\t<li>$title</li>\n";
1391 if ( 'form-table' == $format ) : ?>
1393 <form action="revision.php" method="get">
1395 <div class="tablenav">
1396 <div class="alignleft">
1397 <input type="submit" class="button-secondary" value="<?php esc_attr_e( 'Compare Revisions' ); ?>" />
1398 <input type="hidden" name="action" value="diff" />
1399 <input type="hidden" name="post_type" value="<?php echo esc_attr($post->post_type); ?>" />
1403 <br class="clear" />
1405 <table class="widefat post-revisions" cellspacing="0" id="post-revisions">
1408 <col style="width: 33%" />
1409 <col style="width: 33%" />
1410 <col style="width: 33%" />
1413 <th scope="col"><?php /* translators: column name in revisons */ _ex( 'Old', 'revisions column name' ); ?></th>
1414 <th scope="col"><?php /* translators: column name in revisons */ _ex( 'New', 'revisions column name' ); ?></th>
1415 <th scope="col"><?php /* translators: column name in revisons */ _ex( 'Date Created', 'revisions column name' ); ?></th>
1416 <th scope="col"><?php _e( 'Author' ); ?></th>
1417 <th scope="col" class="action-links"><?php _e( 'Actions' ); ?></th>
1422 <?php echo $rows; ?>
1431 echo "<ul class='post-revisions'>\n";