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 = $post->post_title;
112 if ( !empty($post->post_password) ) {
113 $protected_title_format = apply_filters('protected_title_format', __('Protected: %s'));
114 $title = sprintf($protected_title_format, $title);
115 } else if ( isset($post->post_status) && 'private' == $post->post_status ) {
116 $private_title_format = apply_filters('private_title_format', __('Private: %s'));
117 $title = sprintf($private_title_format, $title);
120 return apply_filters( 'the_title', $title, $post->ID );
124 * Display the Post Global Unique Identifier (guid).
126 * The guid will appear to be a link, but should not be used as an link to the
127 * post. The reason you should not use it as a link, is because of moving the
128 * blog across domains.
132 * @param int $id Optional. Post ID.
134 function the_guid( $id = 0 ) {
135 echo get_the_guid($id);
139 * Retrieve the Post Global Unique Identifier (guid).
141 * The guid will appear to be a link, but should not be used as an link to the
142 * post. The reason you should not use it as a link, is because of moving the
143 * blog across domains.
147 * @param int $id Optional. Post ID.
150 function get_the_guid( $id = 0 ) {
151 $post = &get_post($id);
153 return apply_filters('get_the_guid', $post->guid);
157 * Display the post content.
161 * @param string $more_link_text Optional. Content for when there is more text.
162 * @param string $stripteaser Optional. Teaser content before the more text.
163 * @param string $more_file Optional. Not used.
165 function the_content($more_link_text = null, $stripteaser = 0, $more_file = '') {
166 $content = get_the_content($more_link_text, $stripteaser, $more_file);
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.
179 * @param string $more_file Optional. Not used.
182 function get_the_content($more_link_text = null, $stripteaser = 0, $more_file = '') {
183 global $id, $post, $more, $page, $pages, $multipage, $preview, $pagenow;
185 if ( null === $more_link_text )
186 $more_link_text = __( '(more...)' );
191 // If post password required and it doesn't match the cookie.
192 if ( post_password_required($post) ) {
193 $output = get_the_password_form();
197 if ( $more_file != '' )
200 $file = $pagenow; //$_SERVER['PHP_SELF'];
202 if ( $page > count($pages) ) // if the requested page doesn't exist
203 $page = count($pages); // give them the highest numbered page that DOES exist
205 $content = $pages[$page-1];
206 if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
207 $content = explode($matches[0], $content, 2);
208 if ( !empty($matches[1]) && !empty($more_link_text) )
209 $more_link_text = strip_tags(wp_kses_no_null(trim($matches[1])));
213 $content = array($content);
215 if ( (false !== strpos($post->post_content, '<!--noteaser-->') && ((!$multipage) || ($page==1))) )
217 $teaser = $content[0];
218 if ( ($more) && ($stripteaser) && ($hasTeaser) )
221 if ( count($content) > 1 ) {
223 $output .= '<span id="more-' . $id . '"></span>' . $content[1];
225 if ( ! empty($more_link_text) )
226 $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-$id\" class=\"more-link\">$more_link_text</a>", $more_link_text );
227 $output = force_balance_tags($output);
231 if ( $preview ) // preview fix for javascript bug with foreign languages
232 $output = preg_replace_callback('/\%u([0-9A-F]{4})/', create_function('$match', 'return "&#" . base_convert($match[1], 16, 10) . ";";'), $output);
238 * Display the post excerpt.
241 * @uses apply_filters() Calls 'the_excerpt' hook on post excerpt.
243 function the_excerpt() {
244 echo apply_filters('the_excerpt', get_the_excerpt());
248 * Retrieve the post excerpt.
252 * @param mixed $deprecated Not used.
255 function get_the_excerpt($deprecated = '') {
258 $output = $post->post_excerpt;
259 if ( post_password_required($post) ) {
260 $output = __('There is no excerpt because this is a protected post.');
264 return apply_filters('get_the_excerpt', $output);
268 * Whether post has excerpt.
272 * @param int $id Optional. Post ID.
275 function has_excerpt( $id = 0 ) {
276 $post = &get_post( $id );
277 return ( !empty( $post->post_excerpt ) );
281 * Display the classes for the post div.
285 * @param string|array $class One or more classes to add to the class list.
286 * @param int $post_id An optional post ID.
288 function post_class( $class = '', $post_id = null ) {
289 // Separates classes with a single space, collates classes for post DIV
290 echo 'class="' . join( ' ', get_post_class( $class, $post_id ) ) . '"';
294 * Retrieve the classes for the post div as an array.
296 * The class names are add are many. If the post is a sticky, then the 'sticky'
297 * class name. The class 'hentry' is always added to each post. For each
298 * category, the class will be added with 'category-' with category slug is
299 * added. The tags are the same way as the categories with 'tag-' before the tag
300 * slug. All classes are passed through the filter, 'post_class' with the list
301 * of classes, followed by $class parameter value, with the post ID as the last
306 * @param string|array $class One or more classes to add to the class list.
307 * @param int $post_id An optional post ID.
308 * @return array Array of classes.
310 function get_post_class( $class = '', $post_id = null ) {
311 $post = get_post($post_id);
315 $classes[] = 'post-' . $post->ID;
316 $classes[] = $post->post_type;
318 // sticky for Sticky Posts
319 if ( is_sticky($post->ID) && is_home())
320 $classes[] = 'sticky';
322 // hentry for hAtom compliace
323 $classes[] = 'hentry';
326 foreach ( (array) get_the_category($post->ID) as $cat ) {
327 if ( empty($cat->slug ) )
329 $classes[] = 'category-' . sanitize_html_class($cat->slug, $cat->cat_ID);
333 foreach ( (array) get_the_tags($post->ID) as $tag ) {
334 if ( empty($tag->slug ) )
336 $classes[] = 'tag-' . sanitize_html_class($tag->slug, $tag->term_id);
339 if ( !empty($class) ) {
340 if ( !is_array( $class ) )
341 $class = preg_split('#\s+#', $class);
342 $classes = array_merge($classes, $class);
345 return apply_filters('post_class', $classes, $class, $post_id);
349 * Display the classes for the body element.
353 * @param string|array $class One or more classes to add to the class list.
355 function body_class( $class = '' ) {
356 // Separates classes with a single space, collates classes for body element
357 echo 'class="' . join( ' ', get_body_class( $class ) ) . '"';
361 * Retrieve the classes for the body element as an array.
365 * @param string|array $class One or more classes to add to the class list.
366 * @return array Array of classes.
368 function get_body_class( $class = '' ) {
369 global $wp_query, $wpdb, $current_user;
373 if ( 'rtl' == get_bloginfo('text_direction') )
376 if ( is_front_page() )
381 $classes[] = 'archive';
385 $classes[] = 'search';
387 $classes[] = 'paged';
388 if ( is_attachment() )
389 $classes[] = 'attachment';
391 $classes[] = 'error404';
394 $wp_query->post = $wp_query->posts[0];
395 setup_postdata($wp_query->post);
397 $postID = $wp_query->post->ID;
398 $classes[] = 'single postid-' . $postID;
400 if ( is_attachment() ) {
401 $mime_type = get_post_mime_type();
402 $mime_prefix = array( 'application/', 'image/', 'text/', 'audio/', 'video/', 'music/' );
403 $classes[] = 'attachmentid-' . $postID;
404 $classes[] = 'attachment-' . str_replace($mime_prefix, '', $mime_type);
406 } elseif ( is_archive() ) {
408 $author = $wp_query->get_queried_object();
409 $classes[] = 'author';
410 $classes[] = 'author-' . sanitize_html_class($author->user_nicename , $author->user_id);
411 } elseif ( is_category() ) {
412 $cat = $wp_query->get_queried_object();
413 $classes[] = 'category';
414 $classes[] = 'category-' . sanitize_html_class($cat->slug, $cat->cat_ID);
415 } elseif ( is_tag() ) {
416 $tags = $wp_query->get_queried_object();
418 $classes[] = 'tag-' . sanitize_html_class($tags->slug, $tags->term_id);
420 } elseif ( is_page() ) {
423 $wp_query->post = $wp_query->posts[0];
424 setup_postdata($wp_query->post);
426 $pageID = $wp_query->post->ID;
428 $classes[] = 'page-id-' . $pageID;
430 if ( $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' LIMIT 1", $pageID) ) )
431 $classes[] = 'page-parent';
433 if ( $wp_query->post->post_parent )
434 $classes[] = 'page-child';
435 $classes[] = 'parent-pageid-' . $wp_query->post->post_parent;
437 if ( is_page_template() )
438 $classes[] = 'page-template';
439 $classes[] = 'page-template-' . str_replace( '.php', '-php', get_post_meta( $pageID, '_wp_page_template', true ) );
440 } elseif ( is_search() ) {
441 if ( !empty($wp_query->posts) )
442 $classes[] = 'search-results';
444 $classes[] = 'search-no-results';
447 if ( is_user_logged_in() )
448 $classes[] = 'logged-in';
450 $page = $wp_query->get('page');
452 if ( !$page || $page < 2)
453 $page = $wp_query->get('paged');
455 if ( $page && $page > 1 ) {
456 $classes[] = 'paged-' . $page;
459 $classes[] = 'single-paged-' . $page;
461 $classes[] = 'page-paged-' . $page;
462 elseif ( is_category() )
463 $classes[] = 'category-paged-' . $page;
465 $classes[] = 'tag-paged-' . $page;
467 $classes[] = 'date-paged-' . $page;
468 elseif ( is_author() )
469 $classes[] = 'author-paged-' . $page;
470 elseif ( is_search() )
471 $classes[] = 'search-paged-' . $page;
474 if ( !empty($class) ) {
475 if ( !is_array( $class ) )
476 $class = preg_split('#\s+#', $class);
477 $classes = array_merge($classes, $class);
480 return apply_filters('body_class', $classes, $class);
484 * Whether post requires password and correct password has been provided.
488 * @param int|object $post An optional post. Global $post used if not provided.
489 * @return bool false if a password is not required or the correct password cookie is present, true otherwise.
491 function post_password_required( $post = null ) {
492 $post = get_post($post);
494 if ( empty($post->post_password) )
497 if ( !isset($_COOKIE['wp-postpass_' . COOKIEHASH]) )
500 if ( $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password )
507 * Display "sticky" CSS class, if a post is sticky.
511 * @param int $post_id An optional post ID.
513 function sticky_class( $post_id = null ) {
514 if ( !is_sticky($post_id) )
521 * Page Template Functions for usage in Themes
524 * @subpackage Template
528 * The formatted output of a list of pages.
530 * Displays page links for paginated posts (i.e. includes the <!--nextpage-->.
531 * Quicktag one or more times). This tag must be within The Loop.
533 * The defaults for overwriting are:
534 * 'next_or_number' - Default is 'number' (string). Indicates whether page
535 * numbers should be used. Valid values are number and next.
536 * 'nextpagelink' - Default is 'Next Page' (string). Text for link to next page.
538 * 'previouspagelink' - Default is 'Previous Page' (string). Text for link to
539 * previous page, if available.
540 * 'pagelink' - Default is '%' (String).Format string for page numbers. The % in
541 * the parameter string will be replaced with the page number, so Page %
542 * generates "Page 1", "Page 2", etc. Defaults to %, just the page number.
543 * 'before' - Default is '<p> Pages:' (string). The html or text to prepend to
545 * 'after' - Default is '</p>' (string). The html or text to append to each
547 * 'more_file' - Default is '' (string) Page the links should point to. Defaults
548 * to the current page.
549 * 'link_before' - Default is '' (string). The html or text to prepend to each
550 * Pages link inside the <a> tag.
551 * 'link_after' - Default is '' (string). The html or text to append to each
552 * Pages link inside the <a> tag.
557 * @param string|array $args Optional. Overwrite the defaults.
558 * @return string Formatted output in HTML.
560 function wp_link_pages($args = '') {
562 'before' => '<p>' . __('Pages:'), 'after' => '</p>',
563 'link_before' => '', 'link_after' => '',
564 'next_or_number' => 'number', 'nextpagelink' => __('Next page'),
565 'previouspagelink' => __('Previous page'), 'pagelink' => '%',
566 'more_file' => '', 'echo' => 1
569 $r = wp_parse_args( $args, $defaults );
570 extract( $r, EXTR_SKIP );
572 global $post, $page, $numpages, $multipage, $more, $pagenow;
573 if ( $more_file != '' )
580 if ( 'number' == $next_or_number ) {
582 for ( $i = 1; $i < ($numpages+1); $i = $i + 1 ) {
583 $j = str_replace('%',"$i",$pagelink);
585 if ( ($i != $page) || ((!$more) && ($page==1)) ) {
587 $output .= '<a href="' . get_permalink() . '">';
589 if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )
590 $output .= '<a href="' . get_permalink() . '&page=' . $i . '">';
592 $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged') . '">';
596 $output .= $link_before;
598 $output .= $link_after;
599 if ( ($i != $page) || ((!$more) && ($page==1)) )
609 $output .= '<a href="' . get_permalink() . '">' . $link_before. $previouspagelink . $link_after . '</a>';
611 if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )
612 $output .= '<a href="' . get_permalink() . '&page=' . $i . '">' . $link_before. $previouspagelink . $link_after . '</a>';
614 $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged') . '">' . $link_before. $previouspagelink . $link_after . '</a>';
618 if ( $i <= $numpages && $more ) {
620 $output .= '<a href="' . get_permalink() . '">' . $link_before. $nextpagelink . $link_after . '</a>';
622 if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )
623 $output .= '<a href="' . get_permalink() . '&page=' . $i . '">' . $link_before. $nextpagelink . $link_after . '</a>';
625 $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged') . '">' . $link_before. $nextpagelink . $link_after . '</a>';
641 // Post-meta: Custom per-post fields.
645 * Retrieve post custom meta data field.
649 * @param string $key Meta data key name.
650 * @return string|array Array of values or single value, if only one element exists.
652 function post_custom( $key = '' ) {
653 $custom = get_post_custom();
655 if ( 1 == count($custom[$key]) )
656 return $custom[$key][0];
658 return $custom[$key];
662 * Display list of post custom fields.
664 * @internal This will probably change at some point...
666 * @uses apply_filters() Calls 'the_meta_key' on list item HTML content, with key and value as separate parameters.
668 function the_meta() {
669 if ( $keys = get_post_custom_keys() ) {
670 echo "<ul class='post-meta'>\n";
671 foreach ( (array) $keys as $key ) {
673 if ( '_' == $keyt{0} )
675 $values = array_map('trim', get_post_custom_values($key));
676 $value = implode($values,', ');
677 echo apply_filters('the_meta_key', "<li><span class='post-meta-key'>$key:</span> $value</li>\n", $key, $value);
688 * Retrieve or display list of pages as a dropdown (select list).
692 * @param array|string $args Optional. Override default arguments.
693 * @return string HTML content, if not displaying.
695 function wp_dropdown_pages($args = '') {
697 'depth' => 0, 'child_of' => 0,
698 'selected' => 0, 'echo' => 1,
699 'name' => 'page_id', 'show_option_none' => '', 'show_option_no_change' => '',
700 'option_none_value' => ''
703 $r = wp_parse_args( $args, $defaults );
704 extract( $r, EXTR_SKIP );
706 $pages = get_pages($r);
709 if ( ! empty($pages) ) {
710 $output = "<select name=\"$name\" id=\"$name\">\n";
711 if ( $show_option_no_change )
712 $output .= "\t<option value=\"-1\">$show_option_no_change</option>";
713 if ( $show_option_none )
714 $output .= "\t<option value=\"" . esc_attr($option_none_value) . "\">$show_option_none</option>\n";
715 $output .= walk_page_dropdown_tree($pages, $depth, $r);
716 $output .= "</select>\n";
719 $output = apply_filters('wp_dropdown_pages', $output);
728 * Retrieve or display list of pages in list (li) format.
732 * @param array|string $args Optional. Override default arguments.
733 * @return string HTML content, if not displaying.
735 function wp_list_pages($args = '') {
737 'depth' => 0, 'show_date' => '',
738 'date_format' => get_option('date_format'),
739 'child_of' => 0, 'exclude' => '',
740 'title_li' => __('Pages'), 'echo' => 1,
741 'authors' => '', 'sort_column' => 'menu_order, post_title',
742 'link_before' => '', 'link_after' => ''
745 $r = wp_parse_args( $args, $defaults );
746 extract( $r, EXTR_SKIP );
751 // sanitize, mostly to keep spaces out
752 $r['exclude'] = preg_replace('/[^0-9,]/', '', $r['exclude']);
754 // Allow plugins to filter an array of excluded pages
755 $r['exclude'] = implode(',', apply_filters('wp_list_pages_excludes', explode(',', $r['exclude'])));
758 $r['hierarchical'] = 0;
759 $pages = get_pages($r);
761 if ( !empty($pages) ) {
762 if ( $r['title_li'] )
763 $output .= '<li class="pagenav">' . $r['title_li'] . '<ul>';
766 if ( is_page() || is_attachment() || $wp_query->is_posts_page )
767 $current_page = $wp_query->get_queried_object_id();
768 $output .= walk_page_tree($pages, $r['depth'], $current_page, $r);
770 if ( $r['title_li'] )
771 $output .= '</ul></li>';
774 $output = apply_filters('wp_list_pages', $output);
783 * Display or retrieve list of pages with optional home link.
785 * The arguments are listed below and part of the arguments are for {@link
786 * wp_list_pages()} function. Check that function for more info on those
790 * <li><strong>sort_column</strong> - How to sort the list of pages. Defaults
791 * to page title. Use column for posts table.</li>
792 * <li><strong>menu_class</strong> - Class to use for the div ID which contains
793 * the page list. Defaults to 'menu'.</li>
794 * <li><strong>echo</strong> - Whether to echo list or return it. Defaults to
796 * <li><strong>link_before</strong> - Text before show_home argument text.</li>
797 * <li><strong>link_after</strong> - Text after show_home argument text.</li>
798 * <li><strong>show_home</strong> - If you set this argument, then it will
799 * display the link to the home page. The show_home argument really just needs
800 * to be set to the value of the text of the link.</li>
805 * @param array|string $args
807 function wp_page_menu( $args = array() ) {
808 $defaults = array('sort_column' => 'post_title', 'menu_class' => 'menu', 'echo' => true, 'link_before' => '', 'link_after' => '');
809 $args = wp_parse_args( $args, $defaults );
810 $args = apply_filters( 'wp_page_menu_args', $args );
816 // Show Home in the menu
817 if ( isset($args['show_home']) && ! empty($args['show_home']) ) {
818 if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] )
821 $text = $args['show_home'];
823 if ( is_front_page() && !is_paged() )
824 $class = 'class="current_page_item"';
825 $menu .= '<li ' . $class . '><a href="' . get_option('home') . '">' . $args['link_before'] . $text . $args['link_after'] . '</a></li>';
826 // If the front page is a page, add it to the exclude list
827 if (get_option('show_on_front') == 'page') {
828 if ( !empty( $list_args['exclude'] ) ) {
829 $list_args['exclude'] .= ',';
831 $list_args['exclude'] = '';
833 $list_args['exclude'] .= get_option('page_on_front');
837 $list_args['echo'] = false;
838 $list_args['title_li'] = '';
839 $menu .= str_replace( array( "\r", "\n", "\t" ), '', wp_list_pages($list_args) );
842 $menu = '<ul>' . $menu . '</ul>';
844 $menu = '<div class="' . $args['menu_class'] . '">' . $menu . "</div>\n";
845 $menu = apply_filters( 'wp_page_menu', $menu, $args );
857 * Retrieve HTML list content for page list.
859 * @uses Walker_Page to create HTML list content.
861 * @see Walker_Page::walk() for parameters and return description.
863 function walk_page_tree($pages, $depth, $current_page, $r) {
864 if ( empty($r['walker']) )
865 $walker = new Walker_Page;
867 $walker = $r['walker'];
869 $args = array($pages, $depth, $r, $current_page);
870 return call_user_func_array(array(&$walker, 'walk'), $args);
874 * Retrieve HTML dropdown (select) content for page list.
876 * @uses Walker_PageDropdown to create HTML dropdown content.
878 * @see Walker_PageDropdown::walk() for parameters and return description.
880 function walk_page_dropdown_tree() {
881 $args = func_get_args();
882 if ( empty($args[2]['walker']) ) // the user's options are the third parameter
883 $walker = new Walker_PageDropdown;
885 $walker = $args[2]['walker'];
887 return call_user_func_array(array(&$walker, 'walk'), $args);
895 * Display an attachment page link using an image or icon.
899 * @param int $id Optional. Post ID.
900 * @param bool $fullsize Optional, default is false. Whether to use full size.
901 * @param bool $deprecated Deprecated. Not used.
902 * @param bool $permalink Optional, default is false. Whether to include permalink.
904 function the_attachment_link($id = 0, $fullsize = false, $deprecated = false, $permalink = false) {
906 echo wp_get_attachment_link($id, 'full', $permalink);
908 echo wp_get_attachment_link($id, 'thumbnail', $permalink);
912 * Retrieve an attachment page link using an image or icon, if possible.
915 * @uses apply_filters() Calls 'wp_get_attachment_link' filter on HTML content with same parameters as function.
917 * @param int $id Optional. Post ID.
918 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string.
919 * @param bool $permalink Optional, default is false. Whether to add permalink to image.
920 * @param bool $icon Optional, default is false. Whether to include icon.
921 * @param string $text Optional, default is false. If string, then will be link text.
922 * @return string HTML content.
924 function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false, $text = false) {
926 $_post = & get_post( $id );
928 if ( ('attachment' != $_post->post_type) || !$url = wp_get_attachment_url($_post->ID) )
929 return __('Missing Attachment');
932 $url = get_attachment_link($_post->ID);
934 $post_title = esc_attr($_post->post_title);
937 $link_text = esc_attr($text);
938 } elseif ( ( is_int($size) && $size != 0 ) or ( is_string($size) && $size != 'none' ) or $size != false ) {
939 $link_text = wp_get_attachment_image($id, $size, $icon);
942 if( trim($link_text) == '' )
943 $link_text = $_post->post_title;
945 return apply_filters( 'wp_get_attachment_link', "<a href='$url' title='$post_title'>$link_text</a>", $id, $size, $permalink, $icon, $text );
949 * Retrieve HTML content of attachment image with link.
952 * @deprecated Use {@link wp_get_attachment_link()}
953 * @see wp_get_attachment_link() Use instead.
955 * @param int $id Optional. Post ID.
956 * @param bool $fullsize Optional, default is false. Whether to use full size image.
957 * @param array $max_dims Optional. Max image dimensions.
958 * @param bool $permalink Optional, default is false. Whether to include permalink to image.
961 function get_the_attachment_link($id = 0, $fullsize = false, $max_dims = false, $permalink = false) {
963 $_post = & get_post($id);
965 if ( ('attachment' != $_post->post_type) || !$url = wp_get_attachment_url($_post->ID) )
966 return __('Missing Attachment');
969 $url = get_attachment_link($_post->ID);
971 $post_title = esc_attr($_post->post_title);
973 $innerHTML = get_attachment_innerHTML($_post->ID, $fullsize, $max_dims);
974 return "<a href='$url' title='$post_title'>$innerHTML</a>";
978 * Retrieve icon URL and Path.
981 * @deprecated Use {@link wp_get_attachment_image_src()}
982 * @see wp_get_attachment_image_src() Use instead.
984 * @param int $id Optional. Post ID.
985 * @param bool $fullsize Optional, default to false. Whether to have full image.
986 * @return array Icon URL and full path to file, respectively.
988 function get_attachment_icon_src( $id = 0, $fullsize = false ) {
990 if ( !$post = & get_post($id) )
993 $file = get_attached_file( $post->ID );
995 if ( !$fullsize && $src = wp_get_attachment_thumb_url( $post->ID ) ) {
996 // We have a thumbnail desired, specified and existing
998 $src_file = basename($src);
999 $class = 'attachmentthumb';
1000 } elseif ( wp_attachment_is_image( $post->ID ) ) {
1001 // We have an image without a thumbnail
1003 $src = wp_get_attachment_url( $post->ID );
1004 $src_file = & $file;
1005 $class = 'attachmentimage';
1006 } elseif ( $src = wp_mime_type_icon( $post->ID ) ) {
1007 // No thumb, no image. We'll look for a mime-related icon instead.
1009 $icon_dir = apply_filters( 'icon_dir', get_template_directory() . '/images' );
1010 $src_file = $icon_dir . '/' . basename($src);
1013 if ( !isset($src) || !$src )
1016 return array($src, $src_file);
1020 * Retrieve HTML content of icon attachment image element.
1023 * @deprecated Use {@link wp_get_attachment_image()}
1024 * @see wp_get_attachment_image() Use instead of.
1026 * @param int $id Optional. Post ID.
1027 * @param bool $fullsize Optional, default to false. Whether to have full size image.
1028 * @param array $max_dims Optional. Dimensions of image.
1029 * @return string HTML content.
1031 function get_attachment_icon( $id = 0, $fullsize = false, $max_dims = false ) {
1033 if ( !$post = & get_post($id) )
1036 if ( !$src = get_attachment_icon_src( $post->ID, $fullsize ) )
1039 list($src, $src_file) = $src;
1041 // Do we need to constrain the image?
1042 if ( ($max_dims = apply_filters('attachment_max_dims', $max_dims)) && file_exists($src_file) ) {
1044 $imagesize = getimagesize($src_file);
1046 if (($imagesize[0] > $max_dims[0]) || $imagesize[1] > $max_dims[1] ) {
1047 $actual_aspect = $imagesize[0] / $imagesize[1];
1048 $desired_aspect = $max_dims[0] / $max_dims[1];
1050 if ( $actual_aspect >= $desired_aspect ) {
1051 $height = $actual_aspect * $max_dims[0];
1052 $constraint = "width='{$max_dims[0]}' ";
1053 $post->iconsize = array($max_dims[0], $height);
1055 $width = $max_dims[1] / $actual_aspect;
1056 $constraint = "height='{$max_dims[1]}' ";
1057 $post->iconsize = array($width, $max_dims[1]);
1060 $post->iconsize = array($imagesize[0], $imagesize[1]);
1067 $post_title = esc_attr($post->post_title);
1069 $icon = "<img src='$src' title='$post_title' alt='$post_title' $constraint/>";
1071 return apply_filters( 'attachment_icon', $icon, $post->ID );
1075 * Retrieve HTML content of image element.
1078 * @deprecated Use {@link wp_get_attachment_image()}
1079 * @see wp_get_attachment_image() Use instead.
1081 * @param int $id Optional. Post ID.
1082 * @param bool $fullsize Optional, default to false. Whether to have full size image.
1083 * @param array $max_dims Optional. Dimensions of image.
1086 function get_attachment_innerHTML($id = 0, $fullsize = false, $max_dims = false) {
1088 if ( !$post = & get_post($id) )
1091 if ( $innerHTML = get_attachment_icon($post->ID, $fullsize, $max_dims))
1095 $innerHTML = esc_attr($post->post_title);
1097 return apply_filters('attachment_innerHTML', $innerHTML, $post->ID);
1101 * Wrap attachment in <<p>> element before content.
1104 * @uses apply_filters() Calls 'prepend_attachment' hook on HTML content.
1106 * @param string $content
1109 function prepend_attachment($content) {
1112 if ( empty($post->post_type) || $post->post_type != 'attachment' )
1115 $p = '<p class="attachment">';
1116 // show the medium sized image representation of the attachment if available, and link to the raw file
1117 $p .= wp_get_attachment_link(0, 'medium', false);
1119 $p = apply_filters('prepend_attachment', $p);
1121 return "$p\n$content";
1129 * Retrieve protected post password form content.
1132 * @uses apply_filters() Calls 'the_password_form' filter on output.
1134 * @return string HTML content for password form for password protected post.
1136 function get_the_password_form() {
1138 $label = 'pwbox-'.(empty($post->ID) ? rand() : $post->ID);
1139 $output = '<form action="' . get_option('siteurl') . '/wp-pass.php" method="post">
1140 <p>' . __("This post is password protected. To view it please enter your password below:") . '</p>
1141 <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>
1144 return apply_filters('the_password_form', $output);
1148 * Whether currently in a page template.
1150 * This template tag allows you to determine whether or not you are in a page
1151 * template. You can optional provide a template name and then the check will be
1152 * specific to that template.
1157 * @param string $template The specific template name if specific matching is required.
1158 * @return bool False on failure, true if success.
1160 function is_page_template($template = '') {
1167 $page = $wp_query->get_queried_object();
1168 $custom_fields = get_post_custom_values('_wp_page_template',$page->ID);
1169 $page_template = $custom_fields[0];
1171 // We have no argument passed so just see if a page_template has been specified
1172 if ( empty( $template ) ) {
1173 if (!empty( $page_template ) ) {
1176 } elseif ( $template == $page_template) {
1184 * Retrieve formatted date timestamp of a revision (linked to that revisions's page).
1186 * @package WordPress
1187 * @subpackage Post_Revisions
1192 * @param int|object $revision Revision ID or revision object.
1193 * @param bool $link Optional, default is true. Link to revisions's page?
1194 * @return string i18n formatted datetimestamp or localized 'Current Revision'.
1196 function wp_post_revision_title( $revision, $link = true ) {
1197 if ( !$revision = get_post( $revision ) )
1200 if ( !in_array( $revision->post_type, array( 'post', 'page', 'revision' ) ) )
1203 /* translators: revision date format, see http://php.net/date */
1204 $datef = _x( 'j F, Y @ G:i', 'revision date format');
1205 /* translators: 1: date */
1206 $autosavef = __( '%1$s [Autosave]' );
1207 /* translators: 1: date */
1208 $currentf = __( '%1$s [Current Revision]' );
1210 $date = date_i18n( $datef, strtotime( $revision->post_modified_gmt . ' +0000' ) );
1211 if ( $link && current_user_can( 'edit_post', $revision->ID ) && $link = get_edit_post_link( $revision->ID ) )
1212 $date = "<a href='$link'>$date</a>";
1214 if ( !wp_is_post_revision( $revision ) )
1215 $date = sprintf( $currentf, $date );
1216 elseif ( wp_is_post_autosave( $revision ) )
1217 $date = sprintf( $autosavef, $date );
1223 * Display list of a post's revisions.
1225 * Can output either a UL with edit links or a TABLE with diff interface, and
1226 * restore action links.
1228 * Second argument controls parameters:
1229 * (bool) parent : include the parent (the "Current Revision") in the list.
1230 * (string) format : 'list' or 'form-table'. 'list' outputs UL, 'form-table'
1231 * outputs TABLE with UI.
1232 * (int) right : what revision is currently being viewed - used in
1233 * form-table format.
1234 * (int) left : what revision is currently being diffed against right -
1235 * used in form-table format.
1237 * @package WordPress
1238 * @subpackage Post_Revisions
1241 * @uses wp_get_post_revisions()
1242 * @uses wp_post_revision_title()
1243 * @uses get_edit_post_link()
1244 * @uses get_the_author_meta()
1246 * @todo split into two functions (list, form-table) ?
1248 * @param int|object $post_id Post ID or post object.
1249 * @param string|array $args See description {@link wp_parse_args()}.
1252 function wp_list_post_revisions( $post_id = 0, $args = null ) {
1253 if ( !$post = get_post( $post_id ) )
1256 $defaults = array( 'parent' => false, 'right' => false, 'left' => false, 'format' => 'list', 'type' => 'all' );
1257 extract( wp_parse_args( $args, $defaults ), EXTR_SKIP );
1261 if ( !$autosave = wp_get_post_autosave( $post->ID ) )
1263 $revisions = array( $autosave );
1265 case 'revision' : // just revisions - remove autosave later
1268 if ( !$revisions = wp_get_post_revisions( $post->ID ) )
1273 /* translators: post revision: 1: when, 2: author name */
1274 $titlef = _x( '%1$s by %2$s', 'post revision' );
1277 array_unshift( $revisions, $post );
1281 $can_edit_post = current_user_can( 'edit_post', $post->ID );
1282 foreach ( $revisions as $revision ) {
1283 if ( !current_user_can( 'read_post', $revision->ID ) )
1285 if ( 'revision' === $type && wp_is_post_autosave( $revision ) )
1288 $date = wp_post_revision_title( $revision );
1289 $name = get_the_author_meta( 'display_name', $revision->post_author );
1291 if ( 'form-table' == $format ) {
1293 $left_checked = $left == $revision->ID ? ' checked="checked"' : '';
1295 $left_checked = $right_checked ? ' checked="checked"' : ''; // [sic] (the next one)
1296 $right_checked = $right == $revision->ID ? ' checked="checked"' : '';
1298 $class = $class ? '' : " class='alternate'";
1300 if ( $post->ID != $revision->ID && $can_edit_post )
1301 $actions = '<a href="' . wp_nonce_url( add_query_arg( array( 'revision' => $revision->ID, 'diff' => false, 'action' => 'restore' ) ), "restore-post_$post->ID|$revision->ID" ) . '">' . __( 'Restore' ) . '</a>';
1305 $rows .= "<tr$class>\n";
1306 $rows .= "\t<th style='white-space: nowrap' scope='row'><input type='radio' name='left' value='$revision->ID'$left_checked /><input type='radio' name='right' value='$revision->ID'$right_checked /></th>\n";
1307 $rows .= "\t<td>$date</td>\n";
1308 $rows .= "\t<td>$name</td>\n";
1309 $rows .= "\t<td class='action-links'>$actions</td>\n";
1312 $title = sprintf( $titlef, $date, $name );
1313 $rows .= "\t<li>$title</li>\n";
1317 if ( 'form-table' == $format ) : ?>
1319 <form action="revision.php" method="get">
1321 <div class="tablenav">
1322 <div class="alignleft">
1323 <input type="submit" class="button-secondary" value="<?php esc_attr_e( 'Compare Revisions' ); ?>" />
1324 <input type="hidden" name="action" value="diff" />
1328 <br class="clear" />
1330 <table class="widefat post-revisions" cellspacing="0">
1332 <col style="width: 33%" />
1333 <col style="width: 33%" />
1334 <col style="width: 33%" />
1337 <th scope="col"></th>
1338 <th scope="col"><?php _e( 'Date Created' ); ?></th>
1339 <th scope="col"><?php _e( 'Author' ); ?></th>
1340 <th scope="col" class="action-links"><?php _e( 'Actions' ); ?></th>
1345 <?php echo $rows; ?>
1354 echo "<ul class='post-revisions'>\n";