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.
23 * Retrieve the ID of the current item in the WordPress Loop.
30 function get_the_ID() {
36 * Display or retrieve the current post title with optional content.
40 * @param string $before Optional. Content to prepend to the title.
41 * @param string $after Optional. Content to append to the title.
42 * @param bool $echo Optional, default to true.Whether to display or return.
43 * @return null|string Null on no title. String if $echo parameter is false.
45 function the_title($before = '', $after = '', $echo = true) {
46 $title = get_the_title();
48 if ( strlen($title) == 0 )
51 $title = $before . $title . $after;
60 * Sanitize the current title when retrieving or displaying.
62 * Works like {@link the_title()}, except the parameters can be in a string or
63 * an array. See the function for what can be override in the $args parameter.
65 * The title before it is displayed will have the tags stripped and {@link
66 * esc_attr()} before it is passed to the user or displayed. The default
67 * as with {@link the_title()}, is to display the title.
71 * @param string|array $args Optional. Override the defaults.
72 * @return string|null Null on failure or display. String when echo is false.
74 function the_title_attribute( $args = '' ) {
75 $title = get_the_title();
77 if ( strlen($title) == 0 )
80 $defaults = array('before' => '', 'after' => '', 'echo' => true);
81 $r = wp_parse_args($args, $defaults);
82 extract( $r, EXTR_SKIP );
85 $title = $before . $title . $after;
86 $title = esc_attr(strip_tags($title));
95 * Retrieve post title.
97 * If the post is protected and the visitor is not an admin, then "Protected"
98 * will be displayed before the post title. If the post is private, then
99 * "Private" will be located before the post title.
103 * @param int $id Optional. Post ID.
106 function get_the_title( $id = 0 ) {
107 $post = &get_post($id);
109 $title = isset($post->post_title) ? $post->post_title : '';
110 $id = isset($post->ID) ? $post->ID : (int) $id;
113 if ( !empty($post->post_password) ) {
114 $protected_title_format = apply_filters('protected_title_format', __('Protected: %s'));
115 $title = sprintf($protected_title_format, $title);
116 } else if ( isset($post->post_status) && 'private' == $post->post_status ) {
117 $private_title_format = apply_filters('private_title_format', __('Private: %s'));
118 $title = sprintf($private_title_format, $title);
121 return apply_filters( 'the_title', $title, $id );
125 * Display the Post Global Unique Identifier (guid).
127 * The guid will appear to be a link, but should not be used as an link to the
128 * post. The reason you should not use it as a link, is because of moving the
129 * blog across domains.
131 * Url is escaped to make it xml safe
135 * @param int $id Optional. Post ID.
137 function the_guid( $id = 0 ) {
138 echo esc_url( get_the_guid( $id ) );
142 * Retrieve the Post Global Unique Identifier (guid).
144 * The guid will appear to be a link, but should not be used as an link to the
145 * post. The reason you should not use it as a link, is because of moving the
146 * blog across domains.
150 * @param int $id Optional. Post ID.
153 function get_the_guid( $id = 0 ) {
154 $post = &get_post($id);
156 return apply_filters('get_the_guid', $post->guid);
160 * Display the post content.
164 * @param string $more_link_text Optional. Content for when there is more text.
165 * @param string $stripteaser Optional. Teaser content before the more text.
167 function the_content($more_link_text = null, $stripteaser = 0) {
168 $content = get_the_content($more_link_text, $stripteaser);
169 $content = apply_filters('the_content', $content);
170 $content = str_replace(']]>', ']]>', $content);
175 * Retrieve the post content.
179 * @param string $more_link_text Optional. Content for when there is more text.
180 * @param string $stripteaser Optional. Teaser content before the more text.
183 function get_the_content($more_link_text = null, $stripteaser = 0) {
184 global $id, $post, $more, $page, $pages, $multipage, $preview;
186 if ( null === $more_link_text )
187 $more_link_text = __( '(more...)' );
192 // If post password required and it doesn't match the cookie.
193 if ( post_password_required($post) ) {
194 $output = get_the_password_form();
198 if ( $page > count($pages) ) // if the requested page doesn't exist
199 $page = count($pages); // give them the highest numbered page that DOES exist
201 $content = $pages[$page-1];
202 if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
203 $content = explode($matches[0], $content, 2);
204 if ( !empty($matches[1]) && !empty($more_link_text) )
205 $more_link_text = strip_tags(wp_kses_no_null(trim($matches[1])));
209 $content = array($content);
211 if ( (false !== strpos($post->post_content, '<!--noteaser-->') && ((!$multipage) || ($page==1))) )
213 $teaser = $content[0];
214 if ( ($more) && ($stripteaser) && ($hasTeaser) )
217 if ( count($content) > 1 ) {
219 $output .= '<span id="more-' . $id . '"></span>' . $content[1];
221 if ( ! empty($more_link_text) )
222 $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-$id\" class=\"more-link\">$more_link_text</a>", $more_link_text );
223 $output = force_balance_tags($output);
227 if ( $preview ) // preview fix for javascript bug with foreign languages
228 $output = preg_replace_callback('/\%u([0-9A-F]{4})/', create_function('$match', 'return "&#" . base_convert($match[1], 16, 10) . ";";'), $output);
234 * Display the post excerpt.
237 * @uses apply_filters() Calls 'the_excerpt' hook on post excerpt.
239 function the_excerpt() {
240 echo apply_filters('the_excerpt', get_the_excerpt());
244 * Retrieve the post excerpt.
248 * @param mixed $deprecated Not used.
251 function get_the_excerpt( $deprecated = '' ) {
252 if ( !empty( $deprecated ) )
253 _deprecated_argument( __FUNCTION__, '2.3' );
256 $output = $post->post_excerpt;
257 if ( post_password_required($post) ) {
258 $output = __('There is no excerpt because this is a protected post.');
262 return apply_filters('get_the_excerpt', $output);
266 * Whether post has excerpt.
270 * @param int $id Optional. Post ID.
273 function has_excerpt( $id = 0 ) {
274 $post = &get_post( $id );
275 return ( !empty( $post->post_excerpt ) );
279 * Display the classes for the post div.
283 * @param string|array $class One or more classes to add to the class list.
284 * @param int $post_id An optional post ID.
286 function post_class( $class = '', $post_id = null ) {
287 // Separates classes with a single space, collates classes for post DIV
288 echo 'class="' . join( ' ', get_post_class( $class, $post_id ) ) . '"';
292 * Retrieve the classes for the post div as an array.
294 * The class names are add are many. If the post is a sticky, then the 'sticky'
295 * class name. The class 'hentry' is always added to each post. For each
296 * category, the class will be added with 'category-' with category slug is
297 * added. The tags are the same way as the categories with 'tag-' before the tag
298 * slug. All classes are passed through the filter, 'post_class' with the list
299 * of classes, followed by $class parameter value, with the post ID as the last
304 * @param string|array $class One or more classes to add to the class list.
305 * @param int $post_id An optional post ID.
306 * @return array Array of classes.
308 function get_post_class( $class = '', $post_id = null ) {
309 $post = get_post($post_id);
316 $classes[] = 'post-' . $post->ID;
317 $classes[] = $post->post_type;
318 $classes[] = 'type-' . $post->post_type;
320 // sticky for Sticky Posts
321 if ( is_sticky($post->ID) && is_home() && !is_paged() )
322 $classes[] = 'sticky';
324 // hentry for hAtom compliace
325 $classes[] = 'hentry';
328 foreach ( (array) get_the_category($post->ID) as $cat ) {
329 if ( empty($cat->slug ) )
331 $classes[] = 'category-' . sanitize_html_class($cat->slug, $cat->cat_ID);
335 foreach ( (array) get_the_tags($post->ID) as $tag ) {
336 if ( empty($tag->slug ) )
338 $classes[] = 'tag-' . sanitize_html_class($tag->slug, $tag->term_id);
341 if ( !empty($class) ) {
342 if ( !is_array( $class ) )
343 $class = preg_split('#\s+#', $class);
344 $classes = array_merge($classes, $class);
347 $classes = array_map('esc_attr', $classes);
349 return apply_filters('post_class', $classes, $class, $post->ID);
353 * Display the classes for the body element.
357 * @param string|array $class One or more classes to add to the class list.
359 function body_class( $class = '' ) {
360 // Separates classes with a single space, collates classes for body element
361 echo 'class="' . join( ' ', get_body_class( $class ) ) . '"';
365 * Retrieve the classes for the body element as an array.
369 * @param string|array $class One or more classes to add to the class list.
370 * @return array Array of classes.
372 function get_body_class( $class = '' ) {
373 global $wp_query, $wpdb;
380 if ( is_front_page() )
385 $classes[] = 'archive';
389 $classes[] = 'search';
391 $classes[] = 'paged';
392 if ( is_attachment() )
393 $classes[] = 'attachment';
395 $classes[] = 'error404';
398 $post_id = $wp_query->get_queried_object_id();
399 $post = $wp_query->get_queried_object();
401 $classes[] = 'single';
402 $classes[] = 'single-' . sanitize_html_class($post->post_type, $post_id);
403 $classes[] = 'postid-' . $post_id;
405 if ( is_attachment() ) {
406 $mime_type = get_post_mime_type($post_id);
407 $mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' );
408 $classes[] = 'attachmentid-' . $post_id;
409 $classes[] = 'attachment-' . str_replace( $mime_prefix, '', $mime_type );
411 } elseif ( is_archive() ) {
413 $author = $wp_query->get_queried_object();
414 $classes[] = 'author';
415 $classes[] = 'author-' . sanitize_html_class( $author->user_nicename , $author->ID );
416 } elseif ( is_category() ) {
417 $cat = $wp_query->get_queried_object();
418 $classes[] = 'category';
419 $classes[] = 'category-' . sanitize_html_class( $cat->slug, $cat->cat_ID );
420 } elseif ( is_tag() ) {
421 $tags = $wp_query->get_queried_object();
423 $classes[] = 'tag-' . sanitize_html_class( $tags->slug, $tags->term_id );
425 } elseif ( is_page() ) {
428 $page_id = $wp_query->get_queried_object_id();
430 $post = get_page($page_id);
432 $classes[] = 'page-id-' . $page_id;
434 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) ) )
435 $classes[] = 'page-parent';
437 if ( $post->post_parent ) {
438 $classes[] = 'page-child';
439 $classes[] = 'parent-pageid-' . $post->post_parent;
441 if ( is_page_template() ) {
442 $classes[] = 'page-template';
443 $classes[] = 'page-template-' . sanitize_html_class( str_replace( '.', '-', get_post_meta( $page_id, '_wp_page_template', true ) ), '' );
445 } elseif ( is_search() ) {
446 if ( !empty( $wp_query->posts ) )
447 $classes[] = 'search-results';
449 $classes[] = 'search-no-results';
452 if ( is_user_logged_in() )
453 $classes[] = 'logged-in';
455 $page = $wp_query->get( 'page' );
457 if ( !$page || $page < 2)
458 $page = $wp_query->get( 'paged' );
460 if ( $page && $page > 1 ) {
461 $classes[] = 'paged-' . $page;
464 $classes[] = 'single-paged-' . $page;
466 $classes[] = 'page-paged-' . $page;
467 elseif ( is_category() )
468 $classes[] = 'category-paged-' . $page;
470 $classes[] = 'tag-paged-' . $page;
472 $classes[] = 'date-paged-' . $page;
473 elseif ( is_author() )
474 $classes[] = 'author-paged-' . $page;
475 elseif ( is_search() )
476 $classes[] = 'search-paged-' . $page;
479 if ( !empty( $class ) ) {
480 if ( !is_array( $class ) )
481 $class = preg_split( '#\s+#', $class );
482 $classes = array_merge( $classes, $class );
485 $classes = array_map( 'esc_attr', $classes );
487 return apply_filters( 'body_class', $classes, $class );
491 * Whether post requires password and correct password has been provided.
495 * @param int|object $post An optional post. Global $post used if not provided.
496 * @return bool false if a password is not required or the correct password cookie is present, true otherwise.
498 function post_password_required( $post = null ) {
499 $post = get_post($post);
501 if ( empty($post->post_password) )
504 if ( !isset($_COOKIE['wp-postpass_' . COOKIEHASH]) )
507 if ( $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password )
514 * Display "sticky" CSS class, if a post is sticky.
518 * @param int $post_id An optional post ID.
520 function sticky_class( $post_id = null ) {
521 if ( !is_sticky($post_id) )
528 * Page Template Functions for usage in Themes
531 * @subpackage Template
535 * The formatted output of a list of pages.
537 * Displays page links for paginated posts (i.e. includes the <!--nextpage-->.
538 * Quicktag one or more times). This tag must be within The Loop.
540 * The defaults for overwriting are:
541 * 'next_or_number' - Default is 'number' (string). Indicates whether page
542 * numbers should be used. Valid values are number and next.
543 * 'nextpagelink' - Default is 'Next Page' (string). Text for link to next page.
545 * 'previouspagelink' - Default is 'Previous Page' (string). Text for link to
546 * previous page, if available.
547 * 'pagelink' - Default is '%' (String).Format string for page numbers. The % in
548 * the parameter string will be replaced with the page number, so Page %
549 * generates "Page 1", "Page 2", etc. Defaults to %, just the page number.
550 * 'before' - Default is '<p> Pages:' (string). The html or text to prepend to
552 * 'after' - Default is '</p>' (string). The html or text to append to each
554 * 'link_before' - Default is '' (string). The html or text to prepend to each
555 * Pages link inside the <a> tag. Also prepended to the current item, which
557 * 'link_after' - Default is '' (string). The html or text to append to each
558 * Pages link inside the <a> tag. Also appended to the current item, which
564 * @param string|array $args Optional. Overwrite the defaults.
565 * @return string Formatted output in HTML.
567 function wp_link_pages($args = '') {
569 'before' => '<p>' . __('Pages:'), 'after' => '</p>',
570 'link_before' => '', 'link_after' => '',
571 'next_or_number' => 'number', 'nextpagelink' => __('Next page'),
572 'previouspagelink' => __('Previous page'), 'pagelink' => '%',
576 $r = wp_parse_args( $args, $defaults );
577 $r = apply_filters( 'wp_link_pages_args', $r );
578 extract( $r, EXTR_SKIP );
580 global $post, $page, $numpages, $multipage, $more, $pagenow;
584 if ( 'number' == $next_or_number ) {
586 for ( $i = 1; $i < ($numpages+1); $i = $i + 1 ) {
587 $j = str_replace('%',$i,$pagelink);
589 if ( ($i != $page) || ((!$more) && ($page==1)) ) {
591 $output .= '<a href="' . get_permalink() . '">';
593 if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )
594 $output .= '<a href="' . add_query_arg('page', $i, get_permalink()) . '">';
595 elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID )
596 $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit('page/' . $i, 'single_paged'). '">';
598 $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged') . '">';
602 $output .= $link_before;
604 $output .= $link_after;
605 if ( ($i != $page) || ((!$more) && ($page==1)) )
615 $output .= '<a href="' . get_permalink() . '">';
617 if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )
618 $output .= '<a href="' . add_query_arg('page', $i, get_permalink()) . '">';
619 elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID )
620 $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit('page/' . $i, 'single_paged'). '">';
622 $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged') . '">';
624 $output .= $link_before. $previouspagelink . $link_after . '</a>';
627 if ( $i <= $numpages && $more ) {
629 $output .= '<a href="' . get_permalink() . '">';
631 if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )
632 $output .= '<a href="' . add_query_arg('page', $i, get_permalink()) . '">';
633 elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID )
634 $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit('page/' . $i, 'single_paged'). '">';
636 $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged') . '">';
638 $output .= $link_before. $nextpagelink . $link_after . '</a>';
653 // Post-meta: Custom per-post fields.
657 * Retrieve post custom meta data field.
661 * @param string $key Meta data key name.
662 * @return bool|string|array Array of values or single value, if only one element exists. False will be returned if key does not exist.
664 function post_custom( $key = '' ) {
665 $custom = get_post_custom();
667 if ( !isset( $custom[$key] ) )
669 elseif ( 1 == count($custom[$key]) )
670 return $custom[$key][0];
672 return $custom[$key];
676 * Display list of post custom fields.
678 * @internal This will probably change at some point...
680 * @uses apply_filters() Calls 'the_meta_key' on list item HTML content, with key and value as separate parameters.
682 function the_meta() {
683 if ( $keys = get_post_custom_keys() ) {
684 echo "<ul class='post-meta'>\n";
685 foreach ( (array) $keys as $key ) {
687 if ( '_' == $keyt{0} )
689 $values = array_map('trim', get_post_custom_values($key));
690 $value = implode($values,', ');
691 echo apply_filters('the_meta_key', "<li><span class='post-meta-key'>$key:</span> $value</li>\n", $key, $value);
702 * Retrieve or display list of pages as a dropdown (select list).
706 * @param array|string $args Optional. Override default arguments.
707 * @return string HTML content, if not displaying.
709 function wp_dropdown_pages($args = '') {
711 'depth' => 0, 'child_of' => 0,
712 'selected' => 0, 'echo' => 1,
713 'name' => 'page_id', 'id' => '',
714 'show_option_none' => '', 'show_option_no_change' => '',
715 'option_none_value' => ''
718 $r = wp_parse_args( $args, $defaults );
719 extract( $r, EXTR_SKIP );
721 $pages = get_pages($r);
723 $name = esc_attr($name);
724 // Back-compat with old system where both id and name were based on $name argument
728 if ( ! empty($pages) ) {
729 $output = "<select name=\"$name\" id=\"$id\">\n";
730 if ( $show_option_no_change )
731 $output .= "\t<option value=\"-1\">$show_option_no_change</option>";
732 if ( $show_option_none )
733 $output .= "\t<option value=\"" . esc_attr($option_none_value) . "\">$show_option_none</option>\n";
734 $output .= walk_page_dropdown_tree($pages, $depth, $r);
735 $output .= "</select>\n";
738 $output = apply_filters('wp_dropdown_pages', $output);
747 * Retrieve or display list of pages in list (li) format.
751 * @param array|string $args Optional. Override default arguments.
752 * @return string HTML content, if not displaying.
754 function wp_list_pages($args = '') {
756 'depth' => 0, 'show_date' => '',
757 'date_format' => get_option('date_format'),
758 'child_of' => 0, 'exclude' => '',
759 'title_li' => __('Pages'), 'echo' => 1,
760 'authors' => '', 'sort_column' => 'menu_order, post_title',
761 'link_before' => '', 'link_after' => '', 'walker' => '',
764 $r = wp_parse_args( $args, $defaults );
765 extract( $r, EXTR_SKIP );
770 // sanitize, mostly to keep spaces out
771 $r['exclude'] = preg_replace('/[^0-9,]/', '', $r['exclude']);
773 // Allow plugins to filter an array of excluded pages (but don't put a nullstring into the array)
774 $exclude_array = ( $r['exclude'] ) ? explode(',', $r['exclude']) : array();
775 $r['exclude'] = implode( ',', apply_filters('wp_list_pages_excludes', $exclude_array) );
778 $r['hierarchical'] = 0;
779 $pages = get_pages($r);
781 if ( !empty($pages) ) {
782 if ( $r['title_li'] )
783 $output .= '<li class="pagenav">' . $r['title_li'] . '<ul>';
786 if ( is_page() || is_attachment() || $wp_query->is_posts_page )
787 $current_page = $wp_query->get_queried_object_id();
788 $output .= walk_page_tree($pages, $r['depth'], $current_page, $r);
790 if ( $r['title_li'] )
791 $output .= '</ul></li>';
794 $output = apply_filters('wp_list_pages', $output, $r);
803 * Display or retrieve list of pages with optional home link.
805 * The arguments are listed below and part of the arguments are for {@link
806 * wp_list_pages()} function. Check that function for more info on those
810 * <li><strong>sort_column</strong> - How to sort the list of pages. Defaults
811 * to page title. Use column for posts table.</li>
812 * <li><strong>menu_class</strong> - Class to use for the div ID which contains
813 * the page list. Defaults to 'menu'.</li>
814 * <li><strong>echo</strong> - Whether to echo list or return it. Defaults to
816 * <li><strong>link_before</strong> - Text before show_home argument text.</li>
817 * <li><strong>link_after</strong> - Text after show_home argument text.</li>
818 * <li><strong>show_home</strong> - If you set this argument, then it will
819 * display the link to the home page. The show_home argument really just needs
820 * to be set to the value of the text of the link.</li>
825 * @param array|string $args
827 function wp_page_menu( $args = array() ) {
828 $defaults = array('sort_column' => 'menu_order, post_title', 'menu_class' => 'menu', 'echo' => true, 'link_before' => '', 'link_after' => '');
829 $args = wp_parse_args( $args, $defaults );
830 $args = apply_filters( 'wp_page_menu_args', $args );
836 // Show Home in the menu
837 if ( ! empty($args['show_home']) ) {
838 if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] )
841 $text = $args['show_home'];
843 if ( is_front_page() && !is_paged() )
844 $class = 'class="current_page_item"';
845 $menu .= '<li ' . $class . '><a href="' . home_url( '/' ) . '" title="' . esc_attr($text) . '">' . $args['link_before'] . $text . $args['link_after'] . '</a></li>';
846 // If the front page is a page, add it to the exclude list
847 if (get_option('show_on_front') == 'page') {
848 if ( !empty( $list_args['exclude'] ) ) {
849 $list_args['exclude'] .= ',';
851 $list_args['exclude'] = '';
853 $list_args['exclude'] .= get_option('page_on_front');
857 $list_args['echo'] = false;
858 $list_args['title_li'] = '';
859 $menu .= str_replace( array( "\r", "\n", "\t" ), '', wp_list_pages($list_args) );
862 $menu = '<ul>' . $menu . '</ul>';
864 $menu = '<div class="' . esc_attr($args['menu_class']) . '">' . $menu . "</div>\n";
865 $menu = apply_filters( 'wp_page_menu', $menu, $args );
877 * Retrieve HTML list content for page list.
879 * @uses Walker_Page to create HTML list content.
881 * @see Walker_Page::walk() for parameters and return description.
883 function walk_page_tree($pages, $depth, $current_page, $r) {
884 if ( empty($r['walker']) )
885 $walker = new Walker_Page;
887 $walker = $r['walker'];
889 $args = array($pages, $depth, $r, $current_page);
890 return call_user_func_array(array(&$walker, 'walk'), $args);
894 * Retrieve HTML dropdown (select) content for page list.
896 * @uses Walker_PageDropdown to create HTML dropdown content.
898 * @see Walker_PageDropdown::walk() for parameters and return description.
900 function walk_page_dropdown_tree() {
901 $args = func_get_args();
902 if ( empty($args[2]['walker']) ) // the user's options are the third parameter
903 $walker = new Walker_PageDropdown;
905 $walker = $args[2]['walker'];
907 return call_user_func_array(array(&$walker, 'walk'), $args);
915 * Display an attachment page link using an image or icon.
919 * @param int $id Optional. Post ID.
920 * @param bool $fullsize Optional, default is false. Whether to use full size.
921 * @param bool $deprecated Deprecated. Not used.
922 * @param bool $permalink Optional, default is false. Whether to include permalink.
924 function the_attachment_link( $id = 0, $fullsize = false, $deprecated = false, $permalink = false ) {
925 if ( !empty( $deprecated ) )
926 _deprecated_argument( __FUNCTION__, '2.5' );
929 echo wp_get_attachment_link($id, 'full', $permalink);
931 echo wp_get_attachment_link($id, 'thumbnail', $permalink);
935 * Retrieve an attachment page link using an image or icon, if possible.
938 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
940 * @param int $id Optional. Post ID.
941 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
942 * @param bool $permalink Optional, default is false. Whether to add permalink to image.
943 * @param bool $icon Optional, default is false. Whether to include icon.
944 * @param string $text Optional, default is false. If string, then will be link text.
945 * @return string HTML content.
947 function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false) {
949 $_post = & get_post( $id );
951 if ( ('attachment' != $_post->post_type) || !$url = wp_get_attachment_url($_post->ID) )
952 return __('Missing Attachment');
955 $url = get_attachment_link($_post->ID);
957 $post_title = esc_attr($_post->post_title);
960 $link_text = esc_attr($text);
961 } elseif ( ( is_int($size) && $size != 0 ) or ( is_string($size) && $size != 'none' ) or $size != false ) {
962 $link_text = wp_get_attachment_image($id, $size, $icon);
967 if( trim($link_text) == '' )
968 $link_text = $_post->post_title;
970 return apply_filters( 'wp_get_attachment_link', "<a href='$url' title='$post_title'>$link_text</a>", $id, $size, $permalink, $icon, $text );
974 * Wrap attachment in <<p>> element before content.
977 * @uses apply_filters() Calls 'prepend_attachment' hook on HTML content.
979 * @param string $content
982 function prepend_attachment($content) {
985 if ( empty($post->post_type) || $post->post_type != 'attachment' )
988 $p = '<p class="attachment">';
989 // show the medium sized image representation of the attachment if available, and link to the raw file
990 $p .= wp_get_attachment_link(0, 'medium', false);
992 $p = apply_filters('prepend_attachment', $p);
994 return "$p\n$content";
1002 * Retrieve protected post password form content.
1005 * @uses apply_filters() Calls 'the_password_form' filter on output.
1007 * @return string HTML content for password form for password protected post.
1009 function get_the_password_form() {
1011 $label = 'pwbox-'.(empty($post->ID) ? rand() : $post->ID);
1012 $output = '<form action="' . get_option('siteurl') . '/wp-pass.php" method="post">
1013 <p>' . __("This post is password protected. To view it please enter your password below:") . '</p>
1014 <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>
1017 return apply_filters('the_password_form', $output);
1021 * Whether currently in a page template.
1023 * This template tag allows you to determine if you are in a page template.
1024 * You can optionally provide a template name and then the check will be
1025 * specific to that template.
1030 * @param string $template The specific template name if specific matching is required.
1031 * @return bool False on failure, true if success.
1033 function is_page_template($template = '') {
1040 $page = $wp_query->get_queried_object();
1041 $custom_fields = get_post_custom_values('_wp_page_template',$page->ID);
1042 $page_template = $custom_fields[0];
1044 // We have no argument passed so just see if a page_template has been specified
1045 if ( empty( $template ) ) {
1046 if (!empty( $page_template ) ) {
1049 } elseif ( $template == $page_template) {
1057 * Retrieve formatted date timestamp of a revision (linked to that revisions's page).
1059 * @package WordPress
1060 * @subpackage Post_Revisions
1065 * @param int|object $revision Revision ID or revision object.
1066 * @param bool $link Optional, default is true. Link to revisions's page?
1067 * @return string i18n formatted datetimestamp or localized 'Current Revision'.
1069 function wp_post_revision_title( $revision, $link = true ) {
1070 if ( !$revision = get_post( $revision ) )
1073 if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) )
1076 /* translators: revision date format, see http://php.net/date */
1077 $datef = _x( 'j F, Y @ G:i', 'revision date format');
1078 /* translators: 1: date */
1079 $autosavef = __( '%1$s [Autosave]' );
1080 /* translators: 1: date */
1081 $currentf = __( '%1$s [Current Revision]' );
1083 $date = date_i18n( $datef, strtotime( $revision->post_modified ) );
1084 if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) )
1085 $date = "<a href='$link'>$date</a>";
1087 if ( !wp_is_post_revision( $revision ) )
1088 $date = sprintf( $currentf, $date );
1089 elseif ( wp_is_post_autosave( $revision ) )
1090 $date = sprintf( $autosavef, $date );
1096 * Display list of a post's revisions.
1098 * Can output either a UL with edit links or a TABLE with diff interface, and
1099 * restore action links.
1101 * Second argument controls parameters:
1102 * (bool) parent : include the parent (the "Current Revision") in the list.
1103 * (string) format : 'list' or 'form-table'. 'list' outputs UL, 'form-table'
1104 * outputs TABLE with UI.
1105 * (int) right : what revision is currently being viewed - used in
1106 * form-table format.
1107 * (int) left : what revision is currently being diffed against right -
1108 * used in form-table format.
1110 * @package WordPress
1111 * @subpackage Post_Revisions
1114 * @uses wp_get_post_revisions()
1115 * @uses wp_post_revision_title()
1116 * @uses get_edit_post_link()
1117 * @uses get_the_author_meta()
1119 * @todo split into two functions (list, form-table) ?
1121 * @param int|object $post_id Post ID or post object.
1122 * @param string|array $args See description {@link wp_parse_args()}.
1125 function wp_list_post_revisions( $post_id = 0, $args = null ) {
1126 if ( !$post = get_post( $post_id ) )
1129 $defaults = array( 'parent' => false, 'right' => false, 'left' => false, 'format' => 'list', 'type' => 'all' );
1130 extract( wp_parse_args( $args, $defaults ), EXTR_SKIP );
1134 if ( !$autosave = wp_get_post_autosave( $post->ID ) )
1136 $revisions = array( $autosave );
1138 case 'revision' : // just revisions - remove autosave later
1141 if ( !$revisions = wp_get_post_revisions( $post->ID ) )
1146 /* translators: post revision: 1: when, 2: author name */
1147 $titlef = _x( '%1$s by %2$s', 'post revision' );
1150 array_unshift( $revisions, $post );
1154 $can_edit_post = current_user_can( 'edit_post', $post->ID );
1155 foreach ( $revisions as $revision ) {
1156 if ( !current_user_can( 'read_post', $revision->ID ) )
1158 if ( 'revision' === $type && wp_is_post_autosave( $revision ) )
1161 $date = wp_post_revision_title( $revision );
1162 $name = get_the_author_meta( 'display_name', $revision->post_author );
1164 if ( 'form-table' == $format ) {
1166 $left_checked = $left == $revision->ID ? ' checked="checked"' : '';
1168 $left_checked = $right_checked ? ' checked="checked"' : ''; // [sic] (the next one)
1169 $right_checked = $right == $revision->ID ? ' checked="checked"' : '';
1171 $class = $class ? '' : " class='alternate'";
1173 if ( $post->ID != $revision->ID && $can_edit_post )
1174 $actions = '<a href="' . wp_nonce_url( add_query_arg( array( 'revision' => $revision->ID, 'action' => 'restore' ) ), "restore-post_$post->ID|$revision->ID" ) . '">' . __( 'Restore' ) . '</a>';
1178 $rows .= "<tr$class>\n";
1179 $rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='left' value='$revision->ID'$left_checked /></th>\n";
1180 $rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='right' value='$revision->ID'$right_checked /></th>\n";
1181 $rows .= "\t<td>$date</td>\n";
1182 $rows .= "\t<td>$name</td>\n";
1183 $rows .= "\t<td class='action-links'>$actions</td>\n";
1186 $title = sprintf( $titlef, $date, $name );
1187 $rows .= "\t<li>$title</li>\n";
1191 if ( 'form-table' == $format ) : ?>
1193 <form action="revision.php" method="get">
1195 <div class="tablenav">
1196 <div class="alignleft">
1197 <input type="submit" class="button-secondary" value="<?php esc_attr_e( 'Compare Revisions' ); ?>" />
1198 <input type="hidden" name="action" value="diff" />
1199 <input type="hidden" name="post_type" value="<?php echo esc_attr($post->post_type); ?>" />
1203 <br class="clear" />
1205 <table class="widefat post-revisions" cellspacing="0" id="post-revisions">
1208 <col style="width: 33%" />
1209 <col style="width: 33%" />
1210 <col style="width: 33%" />
1213 <th scope="col"><?php /* translators: column name in revisons */ _ex( 'Old', 'revisions column name' ); ?></th>
1214 <th scope="col"><?php /* translators: column name in revisons */ _ex( 'New', 'revisions column name' ); ?></th>
1215 <th scope="col"><?php /* translators: column name in revisons */ _ex( 'Date Created', 'revisions column name' ); ?></th>
1216 <th scope="col"><?php _e( 'Author' ); ?></th>
1217 <th scope="col" class="action-links"><?php _e( 'Actions' ); ?></th>
1222 <?php echo $rows; ?>
1231 echo "<ul class='post-revisions'>\n";