3 * General template tags that can go anywhere in a template.
10 * Load header template.
12 * Includes the header template for a theme or if a name is specified then a
13 * specialised header will be included. If the theme contains no header.php file
14 * then the header from the default theme will be included.
16 * For the parameter, if the file is called "header-special.php" then specify
19 * @uses locate_template()
21 * @uses do_action() Calls 'get_header' action.
23 * @param string $name The name of the specialised header.
25 function get_header( $name = null ) {
26 do_action( 'get_header', $name );
30 $templates[] = "header-{$name}.php";
32 $templates[] = "header.php";
34 if ('' == locate_template($templates, true))
35 load_template( get_theme_root() . '/default/header.php');
39 * Load footer template.
41 * Includes the footer template for a theme or if a name is specified then a
42 * specialised footer will be included. If the theme contains no footer.php file
43 * then the footer from the default theme will be included.
45 * For the parameter, if the file is called "footer-special.php" then specify
48 * @uses locate_template()
50 * @uses do_action() Calls 'get_footer' action.
52 * @param string $name The name of the specialised footer.
54 function get_footer( $name = null ) {
55 do_action( 'get_footer', $name );
59 $templates[] = "footer-{$name}.php";
61 $templates[] = "footer.php";
63 if ('' == locate_template($templates, true))
64 load_template( get_theme_root() . '/default/footer.php');
68 * Load sidebar template.
70 * Includes the sidebar template for a theme or if a name is specified then a
71 * specialised sidebar will be included. If the theme contains no sidebar.php
72 * file then the sidebar from the default theme will be included.
74 * For the parameter, if the file is called "sidebar-special.php" then specify
77 * @uses locate_template()
79 * @uses do_action() Calls 'get_sidebar' action.
81 * @param string $name The name of the specialised sidebar.
83 function get_sidebar( $name = null ) {
84 do_action( 'get_sidebar', $name );
88 $templates[] = "sidebar-{$name}.php";
90 $templates[] = "sidebar.php";
92 if ('' == locate_template($templates, true))
93 load_template( get_theme_root() . '/default/sidebar.php');
97 * Display search form.
99 * Will first attempt to locate the searchform.php file in either the child or
100 * the parent, then load it. If it doesn't exist, then the default search form
101 * will be displayed. The default search form is HTML, which will be displayed.
102 * There is a filter applied to the search form HTML in order to edit or replace
103 * it. The filter is 'get_search_form'.
105 * This function is primarily used by themes which want to hardcode the search
106 * form into the sidebar and also by the search widget in WordPress.
108 * There is also an action that is called whenever the function is run called,
109 * 'get_search_form'. This can be useful for outputting JavaScript that the
110 * search relies on or various formatting that applies to the beginning of the
111 * search. To give a few examples of what it can be used for.
115 function get_search_form() {
116 do_action( 'get_search_form' );
118 $search_form_template = locate_template(array('searchform.php'));
119 if ( '' != $search_form_template ) {
120 require($search_form_template);
124 $form = '<form role="search" method="get" id="searchform" action="' . get_option('home') . '/" >
125 <div><label class="screen-reader-text" for="s">' . __('Search for:') . '</label>
126 <input type="text" value="' . esc_attr(apply_filters('the_search_query', get_search_query())) . '" name="s" id="s" />
127 <input type="submit" id="searchsubmit" value="'. esc_attr__('Search') .'" />
131 echo apply_filters('get_search_form', $form);
135 * Display the Log In/Out link.
137 * Displays a link, which allows the user to navigate to the Log In page to log in
138 * or log out depending on whether or not they are currently logged in.
141 * @uses apply_filters() Calls 'loginout' hook on HTML link content.
143 * @param string $redirect Optional path to redirect to on login/logout.
145 function wp_loginout($redirect = '') {
146 if ( ! is_user_logged_in() )
147 $link = '<a href="' . esc_url( wp_login_url($redirect) ) . '">' . __('Log in') . '</a>';
149 $link = '<a href="' . esc_url( wp_logout_url($redirect) ) . '">' . __('Log out') . '</a>';
151 echo apply_filters('loginout', $link);
155 * Returns the Log Out URL.
157 * Returns the URL that allows the user to log out of the site
160 * @uses wp_nonce_url() To protect against CSRF
161 * @uses site_url() To generate the log in URL
162 * @uses apply_filters() calls 'logout_url' hook on final logout url
164 * @param string $redirect Path to redirect to on logout.
166 function wp_logout_url($redirect = '') {
167 $args = array( 'action' => 'logout' );
168 if ( !empty($redirect) ) {
169 $args['redirect_to'] = $redirect;
172 $logout_url = add_query_arg($args, site_url('wp-login.php', 'login'));
173 $logout_url = wp_nonce_url( $logout_url, 'log-out' );
175 return apply_filters('logout_url', $logout_url, $redirect);
179 * Returns the Log In URL.
181 * Returns the URL that allows the user to log in to the site
184 * @uses site_url() To generate the log in URL
185 * @uses apply_filters() calls 'login_url' hook on final login url
187 * @param string $redirect Path to redirect to on login.
189 function wp_login_url($redirect = '') {
190 $login_url = site_url('wp-login.php', 'login');
192 if ( !empty($redirect) ) {
193 $login_url = add_query_arg('redirect_to', urlencode($redirect), $login_url);
196 return apply_filters('login_url', $login_url, $redirect);
200 * Returns the Lost Password URL.
202 * Returns the URL that allows the user to retrieve the lost password
205 * @uses site_url() To generate the lost password URL
206 * @uses apply_filters() calls 'lostpassword_url' hook on the lostpassword url
208 * @param string $redirect Path to redirect to on login.
210 function wp_lostpassword_url($redirect = '') {
211 $args = array( 'action' => 'lostpassword' );
212 if ( !empty($redirect) ) {
213 $args['redirect_to'] = $redirect;
216 $lostpassword_url = add_query_arg($args, site_url('wp-login.php', 'login'));
217 return apply_filters('lostpassword_url', $lostpassword_url, $redirect);
221 * Display the Registration or Admin link.
223 * Display a link which allows the user to navigate to the registration page if
224 * not logged in and registration is enabled or to the dashboard if logged in.
227 * @uses apply_filters() Calls 'register' hook on register / admin link content.
229 * @param string $before Text to output before the link (defaults to <li>).
230 * @param string $after Text to output after the link (defaults to </li>).
232 function wp_register( $before = '<li>', $after = '</li>' ) {
234 if ( ! is_user_logged_in() ) {
235 if ( get_option('users_can_register') )
236 $link = $before . '<a href="' . site_url('wp-login.php?action=register', 'login') . '">' . __('Register') . '</a>' . $after;
240 $link = $before . '<a href="' . admin_url() . '">' . __('Site Admin') . '</a>' . $after;
243 echo apply_filters('register', $link);
247 * Theme container function for the 'wp_meta' action.
249 * The 'wp_meta' action can have several purposes, depending on how you use it,
250 * but one purpose might have been to allow for theme switching.
253 * @link http://trac.wordpress.org/ticket/1458 Explanation of 'wp_meta' action.
254 * @uses do_action() Calls 'wp_meta' hook.
257 do_action('wp_meta');
261 * Display information about the blog.
263 * @see get_bloginfo() For possible values for the parameter.
266 * @param string $show What to display.
268 function bloginfo($show='') {
269 echo get_bloginfo($show, 'display');
273 * Retrieve information about the blog.
275 * Some show parameter values are deprecated and will be removed in future
276 * versions. Care should be taken to check the function contents and know what
277 * the deprecated blog info options are. Options without "// DEPRECATED" are
278 * the preferred and recommended ways to get the information.
280 * The possible values for the 'show' parameter are listed below.
282 * <li><strong>url<strong> - Blog URI to homepage.</li>
283 * <li><strong>wpurl</strong> - Blog URI path to WordPress.</li>
284 * <li><strong>description</strong> - Secondary title</li>
287 * The feed URL options can be retrieved from 'rdf_url' (RSS 0.91),
288 * 'rss_url' (RSS 1.0), 'rss2_url' (RSS 2.0), or 'atom_url' (Atom feed). The
289 * comment feeds can be retrieved from the 'comments_atom_url' (Atom comment
290 * feed) or 'comments_rss2_url' (RSS 2.0 comment feed).
292 * There are many other options and you should check the function contents:
297 * @param string $show Blog info to retrieve.
298 * @param string $filter How to filter what is retrieved.
299 * @return string Mostly string values, might be empty.
301 function get_bloginfo($show = '', $filter = 'raw') {
305 case 'home' : // DEPRECATED
306 case 'siteurl' : // DEPRECATED
307 $output = get_option('home');
310 $output = get_option('siteurl');
313 $output = get_option('blogdescription');
316 $output = get_feed_link('rdf');
319 $output = get_feed_link('rss');
322 $output = get_feed_link('rss2');
325 $output = get_feed_link('atom');
327 case 'comments_atom_url':
328 $output = get_feed_link('comments_atom');
330 case 'comments_rss2_url':
331 $output = get_feed_link('comments_rss2');
334 $output = get_option('siteurl') .'/xmlrpc.php';
336 case 'stylesheet_url':
337 $output = get_stylesheet_uri();
339 case 'stylesheet_directory':
340 $output = get_stylesheet_directory_uri();
342 case 'template_directory':
344 $output = get_template_directory_uri();
347 $output = get_option('admin_email');
350 $output = get_option('blog_charset');
351 if ('' == $output) $output = 'UTF-8';
354 $output = get_option('html_type');
358 $output = $wp_version;
361 $output = get_locale();
362 $output = str_replace('_', '-', $output);
364 case 'text_direction':
366 $output = $wp_locale->text_direction;
370 $output = get_option('blogname');
375 if (strpos($show, 'url') === false &&
376 strpos($show, 'directory') === false &&
377 strpos($show, 'home') === false)
380 if ( 'display' == $filter ) {
382 $output = apply_filters('bloginfo_url', $output, $show);
384 $output = apply_filters('bloginfo', $output, $show);
391 * Display or retrieve page title for all areas of blog.
393 * By default, the page title will display the separator before the page title,
394 * so that the blog title will be before the page title. This is not good for
395 * title display, since the blog title shows up on most tabs and not what is
396 * important, which is the page that the user is looking at.
398 * There are also SEO benefits to having the blog title after or to the 'right'
399 * or the page title. However, it is mostly common sense to have the blog title
400 * to the right with most browsers supporting tabs. You can achieve this by
401 * using the seplocation parameter and setting the value to 'right'. This change
402 * was introduced around 2.5.0, in case backwards compatibility of themes is
407 * @param string $sep Optional, default is '»'. How to separate the various items within the page title.
408 * @param bool $display Optional, default is true. Whether to display or retrieve title.
409 * @param string $seplocation Optional. Direction to display title, 'right'.
410 * @return string|null String on retrieve, null when displaying.
412 function wp_title($sep = '»', $display = true, $seplocation = '') {
413 global $wpdb, $wp_locale, $wp_query;
415 $cat = get_query_var('cat');
416 $tag = get_query_var('tag_id');
417 $category_name = get_query_var('category_name');
418 $author = get_query_var('author');
419 $author_name = get_query_var('author_name');
420 $m = get_query_var('m');
421 $year = get_query_var('year');
422 $monthnum = get_query_var('monthnum');
423 $day = get_query_var('day');
424 $search = get_query_var('s');
427 $t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary
429 // If there's a category
430 if ( !empty($cat) ) {
431 // category exclusion
432 if ( !stristr($cat,'-') )
433 $title = apply_filters('single_cat_title', get_the_category_by_ID($cat));
434 } elseif ( !empty($category_name) ) {
435 if ( stristr($category_name,'/') ) {
436 $category_name = explode('/',$category_name);
437 if ( $category_name[count($category_name)-1] )
438 $category_name = $category_name[count($category_name)-1]; // no trailing slash
440 $category_name = $category_name[count($category_name)-2]; // there was a trailling slash
442 $cat = get_term_by('slug', $category_name, 'category', OBJECT, 'display');
444 $title = apply_filters('single_cat_title', $cat->name);
447 if ( !empty($tag) ) {
448 $tag = get_term($tag, 'post_tag', OBJECT, 'display');
449 if ( is_wp_error( $tag ) )
451 if ( ! empty($tag->name) )
452 $title = apply_filters('single_tag_title', $tag->name);
455 // If there's an author
456 if ( !empty($author) ) {
457 $title = get_userdata($author);
458 $title = $title->display_name;
460 if ( !empty($author_name) ) {
461 // We do a direct query here because we don't cache by nicename.
462 $title = $wpdb->get_var($wpdb->prepare("SELECT display_name FROM $wpdb->users WHERE user_nicename = %s", $author_name));
465 // If there's a month
467 $my_year = substr($m, 0, 4);
468 $my_month = $wp_locale->get_month(substr($m, 4, 2));
469 $my_day = intval(substr($m, 6, 2));
470 $title = "$my_year" . ($my_month ? "$t_sep$my_month" : "") . ($my_day ? "$t_sep$my_day" : "");
473 if ( !empty($year) ) {
475 if ( !empty($monthnum) )
476 $title .= "$t_sep" . $wp_locale->get_month($monthnum);
478 $title .= "$t_sep" . zeroise($day, 2);
481 // If there is a post
482 if ( is_single() || ( is_home() && !is_front_page() ) || ( is_page() && !is_front_page() ) ) {
483 $post = $wp_query->get_queried_object();
484 $title = strip_tags( apply_filters( 'single_post_title', $post->post_title ) );
487 // If there's a taxonomy
489 $taxonomy = get_query_var( 'taxonomy' );
490 $tax = get_taxonomy( $taxonomy );
492 $term = $wp_query->get_queried_object();
494 $title = "$tax$t_sep$term";
499 /* translators: 1: separator, 2: search phrase */
500 $title = sprintf(__('Search Results %1$s %2$s'), $t_sep, strip_tags($search));
504 $title = __('Page not found');
508 if ( !empty($title) )
511 // Determines position of the separator and direction of the breadcrumb
512 if ( 'right' == $seplocation ) { // sep on right, so reverse the order
513 $title_array = explode( $t_sep, $title );
514 $title_array = array_reverse( $title_array );
515 $title = implode( " $sep ", $title_array ) . $prefix;
517 $title_array = explode( $t_sep, $title );
518 $title = $prefix . implode( " $sep ", $title_array );
521 $title = apply_filters('wp_title', $title, $sep, $seplocation);
532 * Display or retrieve page title for post.
534 * This is optimized for single.php template file for displaying the post title.
535 * Only useful for posts, does not support pages for example.
537 * It does not support placing the separator after the title, but by leaving the
538 * prefix parameter empty, you can set the title separator manually. The prefix
539 * does not automatically place a space between the prefix, so if there should
540 * be a space, the parameter value will need to have it at the end.
545 * @param string $prefix Optional. What to display before the title.
546 * @param bool $display Optional, default is true. Whether to display or retrieve title.
547 * @return string|null Title when retrieving, null when displaying or failure.
549 function single_post_title($prefix = '', $display = true) {
551 $p = get_query_var('p');
552 $name = get_query_var('name');
554 if ( intval($p) || '' != $name ) {
556 $p = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_name = %s", $name));
557 $post = & get_post($p);
558 $title = $post->post_title;
559 $title = apply_filters('single_post_title', $title);
561 echo $prefix.strip_tags($title);
563 return strip_tags($title);
568 * Display or retrieve page title for category archive.
570 * This is useful for category template file or files, because it is optimized
571 * for category page title and with less overhead than {@link wp_title()}.
573 * It does not support placing the separator after the title, but by leaving the
574 * prefix parameter empty, you can set the title separator manually. The prefix
575 * does not automatically place a space between the prefix, so if there should
576 * be a space, the parameter value will need to have it at the end.
580 * @param string $prefix Optional. What to display before the title.
581 * @param bool $display Optional, default is true. Whether to display or retrieve title.
582 * @return string|null Title when retrieving, null when displaying or failure.
584 function single_cat_title($prefix = '', $display = true ) {
585 $cat = intval( get_query_var('cat') );
586 if ( !empty($cat) && !(strtoupper($cat) == 'ALL') ) {
587 $my_cat_name = apply_filters('single_cat_title', get_the_category_by_ID($cat));
588 if ( !empty($my_cat_name) ) {
590 echo $prefix.strip_tags($my_cat_name);
592 return strip_tags($my_cat_name);
594 } else if ( is_tag() ) {
595 return single_tag_title($prefix, $display);
600 * Display or retrieve page title for tag post archive.
602 * Useful for tag template files for displaying the tag page title. It has less
603 * overhead than {@link wp_title()}, because of its limited implementation.
605 * It does not support placing the separator after the title, but by leaving the
606 * prefix parameter empty, you can set the title separator manually. The prefix
607 * does not automatically place a space between the prefix, so if there should
608 * be a space, the parameter value will need to have it at the end.
612 * @param string $prefix Optional. What to display before the title.
613 * @param bool $display Optional, default is true. Whether to display or retrieve title.
614 * @return string|null Title when retrieving, null when displaying or failure.
616 function single_tag_title($prefix = '', $display = true ) {
620 $tag_id = intval( get_query_var('tag_id') );
622 if ( !empty($tag_id) ) {
623 $my_tag = &get_term($tag_id, 'post_tag', OBJECT, 'display');
624 if ( is_wp_error( $my_tag ) )
626 $my_tag_name = apply_filters('single_tag_title', $my_tag->name);
627 if ( !empty($my_tag_name) ) {
629 echo $prefix . $my_tag_name;
637 * Display or retrieve page title for post archive based on date.
639 * Useful for when the template only needs to display the month and year, if
640 * either are available. Optimized for just this purpose, so if it is all that
641 * is needed, should be better than {@link wp_title()}.
643 * It does not support placing the separator after the title, but by leaving the
644 * prefix parameter empty, you can set the title separator manually. The prefix
645 * does not automatically place a space between the prefix, so if there should
646 * be a space, the parameter value will need to have it at the end.
650 * @param string $prefix Optional. What to display before the title.
651 * @param bool $display Optional, default is true. Whether to display or retrieve title.
652 * @return string|null Title when retrieving, null when displaying or failure.
654 function single_month_title($prefix = '', $display = true ) {
657 $m = get_query_var('m');
658 $year = get_query_var('year');
659 $monthnum = get_query_var('monthnum');
661 if ( !empty($monthnum) && !empty($year) ) {
663 $my_month = $wp_locale->get_month($monthnum);
664 } elseif ( !empty($m) ) {
665 $my_year = substr($m, 0, 4);
666 $my_month = $wp_locale->get_month(substr($m, 4, 2));
669 if ( empty($my_month) )
672 $result = $prefix . $my_month . $prefix . $my_year;
680 * Retrieve archive link content based on predefined or custom code.
682 * The format can be one of four styles. The 'link' for head element, 'option'
683 * for use in the select element, 'html' for use in list (either ol or ul HTML
684 * elements). Custom content is also supported using the before and after
687 * The 'link' format uses the link HTML element with the <em>archives</em>
688 * relationship. The before and after parameters are not used. The text
689 * parameter is used to describe the link.
691 * The 'option' format uses the option HTML element for use in select element.
692 * The value is the url parameter and the before and after parameters are used
693 * between the text description.
695 * The 'html' format, which is the default, uses the li HTML element for use in
696 * the list HTML elements. The before parameter is before the link and the after
697 * parameter is after the closing link.
699 * The custom format uses the before parameter before the link ('a' HTML
700 * element) and the after parameter after the closing link tag. If the above
701 * three values for the format are not used, then custom format is assumed.
705 * @link http://icecode.com/ link navigation hack by Orien
707 * @param string $url URL to archive.
708 * @param string $text Archive text description.
709 * @param string $format Optional, default is 'html'. Can be 'link', 'option', 'html', or custom.
710 * @param string $before Optional.
711 * @param string $after Optional.
712 * @return string HTML link content for archive.
714 function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') {
715 $text = wptexturize($text);
716 $title_text = esc_attr($text);
717 $url = esc_url($url);
719 if ('link' == $format)
720 $link_html = "\t<link rel='archives' title='$title_text' href='$url' />\n";
721 elseif ('option' == $format)
722 $link_html = "\t<option value='$url'>$before $text $after</option>\n";
723 elseif ('html' == $format)
724 $link_html = "\t<li>$before<a href='$url' title='$title_text'>$text</a>$after</li>\n";
726 $link_html = "\t$before<a href='$url' title='$title_text'>$text</a>$after\n";
728 $link_html = apply_filters( "get_archives_link", $link_html );
734 * Display archive links based on type and format.
736 * The 'type' argument offers a few choices and by default will display monthly
737 * archive links. The other options for values are 'daily', 'weekly', 'monthly',
738 * 'yearly', 'postbypost' or 'alpha'. Both 'postbypost' and 'alpha' display the
739 * same archive link list, the difference between the two is that 'alpha'
740 * will order by post title and 'postbypost' will order by post date.
742 * The date archives will logically display dates with links to the archive post
743 * page. The 'postbypost' and 'alpha' values for 'type' argument will display
746 * The 'limit' argument will only display a limited amount of links, specified
747 * by the 'limit' integer value. By default, there is no limit. The
748 * 'show_post_count' argument will show how many posts are within the archive.
749 * By default, the 'show_post_count' argument is set to false.
751 * For the 'format', 'before', and 'after' arguments, see {@link
752 * get_archives_link()}. The values of these arguments have to do with that
757 * @param string|array $args Optional. Override defaults.
759 function wp_get_archives($args = '') {
760 global $wpdb, $wp_locale;
763 'type' => 'monthly', 'limit' => '',
764 'format' => 'html', 'before' => '',
765 'after' => '', 'show_post_count' => false,
769 $r = wp_parse_args( $args, $defaults );
770 extract( $r, EXTR_SKIP );
775 if ( '' != $limit ) {
776 $limit = absint($limit);
777 $limit = ' LIMIT '.$limit;
780 // this is what will separate dates on weekly archive links
781 $archive_week_separator = '–';
783 // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride
784 $archive_date_format_over_ride = 0;
786 // options for daily archive (only if you over-ride the general date format)
787 $archive_day_date_format = 'Y/m/d';
789 // options for weekly archive (only if you over-ride the general date format)
790 $archive_week_start_date_format = 'Y/m/d';
791 $archive_week_end_date_format = 'Y/m/d';
793 if ( !$archive_date_format_over_ride ) {
794 $archive_day_date_format = get_option('date_format');
795 $archive_week_start_date_format = get_option('date_format');
796 $archive_week_end_date_format = get_option('date_format');
800 $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r );
801 $join = apply_filters('getarchives_join', "", $r);
805 if ( 'monthly' == $type ) {
806 $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC $limit";
808 $cache = wp_cache_get( 'wp_get_archives' , 'general');
809 if ( !isset( $cache[ $key ] ) ) {
810 $arcresults = $wpdb->get_results($query);
811 $cache[ $key ] = $arcresults;
812 wp_cache_add( 'wp_get_archives', $cache, 'general' );
814 $arcresults = $cache[ $key ];
817 $afterafter = $after;
818 foreach ( (array) $arcresults as $arcresult ) {
819 $url = get_month_link( $arcresult->year, $arcresult->month );
820 $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year);
821 if ( $show_post_count )
822 $after = ' ('.$arcresult->posts.')' . $afterafter;
823 $output .= get_archives_link($url, $text, $format, $before, $after);
826 } elseif ('yearly' == $type) {
827 $query = "SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date) ORDER BY post_date DESC $limit";
829 $cache = wp_cache_get( 'wp_get_archives' , 'general');
830 if ( !isset( $cache[ $key ] ) ) {
831 $arcresults = $wpdb->get_results($query);
832 $cache[ $key ] = $arcresults;
833 wp_cache_add( 'wp_get_archives', $cache, 'general' );
835 $arcresults = $cache[ $key ];
838 $afterafter = $after;
839 foreach ( (array) $arcresults as $arcresult) {
840 $url = get_year_link($arcresult->year);
841 $text = sprintf('%d', $arcresult->year);
842 if ($show_post_count)
843 $after = ' ('.$arcresult->posts.')' . $afterafter;
844 $output .= get_archives_link($url, $text, $format, $before, $after);
847 } elseif ( 'daily' == $type ) {
848 $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date DESC $limit";
850 $cache = wp_cache_get( 'wp_get_archives' , 'general');
851 if ( !isset( $cache[ $key ] ) ) {
852 $arcresults = $wpdb->get_results($query);
853 $cache[ $key ] = $arcresults;
854 wp_cache_add( 'wp_get_archives', $cache, 'general' );
856 $arcresults = $cache[ $key ];
859 $afterafter = $after;
860 foreach ( (array) $arcresults as $arcresult ) {
861 $url = get_day_link($arcresult->year, $arcresult->month, $arcresult->dayofmonth);
862 $date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $arcresult->year, $arcresult->month, $arcresult->dayofmonth);
863 $text = mysql2date($archive_day_date_format, $date);
864 if ($show_post_count)
865 $after = ' ('.$arcresult->posts.')'.$afterafter;
866 $output .= get_archives_link($url, $text, $format, $before, $after);
869 } elseif ( 'weekly' == $type ) {
870 $start_of_week = get_option('start_of_week');
871 $query = "SELECT DISTINCT WEEK(post_date, $start_of_week) AS `week`, YEAR(post_date) AS yr, DATE_FORMAT(post_date, '%Y-%m-%d') AS yyyymmdd, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY WEEK(post_date, $start_of_week), YEAR(post_date) ORDER BY post_date DESC $limit";
873 $cache = wp_cache_get( 'wp_get_archives' , 'general');
874 if ( !isset( $cache[ $key ] ) ) {
875 $arcresults = $wpdb->get_results($query);
876 $cache[ $key ] = $arcresults;
877 wp_cache_add( 'wp_get_archives', $cache, 'general' );
879 $arcresults = $cache[ $key ];
882 $afterafter = $after;
884 foreach ( (array) $arcresults as $arcresult ) {
885 if ( $arcresult->week != $arc_w_last ) {
886 $arc_year = $arcresult->yr;
887 $arc_w_last = $arcresult->week;
888 $arc_week = get_weekstartend($arcresult->yyyymmdd, get_option('start_of_week'));
889 $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']);
890 $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']);
891 $url = sprintf('%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', get_option('home'), '', '?', '=', $arc_year, '&', '=', $arcresult->week);
892 $text = $arc_week_start . $archive_week_separator . $arc_week_end;
893 if ($show_post_count)
894 $after = ' ('.$arcresult->posts.')'.$afterafter;
895 $output .= get_archives_link($url, $text, $format, $before, $after);
899 } elseif ( ( 'postbypost' == $type ) || ('alpha' == $type) ) {
900 $orderby = ('alpha' == $type) ? "post_title ASC " : "post_date DESC ";
901 $query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit";
903 $cache = wp_cache_get( 'wp_get_archives' , 'general');
904 if ( !isset( $cache[ $key ] ) ) {
905 $arcresults = $wpdb->get_results($query);
906 $cache[ $key ] = $arcresults;
907 wp_cache_add( 'wp_get_archives', $cache, 'general' );
909 $arcresults = $cache[ $key ];
912 foreach ( (array) $arcresults as $arcresult ) {
913 if ( $arcresult->post_date != '0000-00-00 00:00:00' ) {
914 $url = get_permalink($arcresult);
915 $arc_title = $arcresult->post_title;
917 $text = strip_tags(apply_filters('the_title', $arc_title));
919 $text = $arcresult->ID;
920 $output .= get_archives_link($url, $text, $format, $before, $after);
932 * Get number of days since the start of the week.
935 * @usedby get_calendar()
937 * @param int $num Number of day.
938 * @return int Days since the start of the week.
940 function calendar_week_mod($num) {
942 return ($num - $base*floor($num/$base));
946 * Display calendar with days that have posts as links.
948 * The calendar is cached, which will be retrieved, if it exists. If there are
949 * no posts for the month, then it will not be displayed.
953 * @param bool $initial Optional, default is true. Use initial calendar names.
955 function get_calendar($initial = true) {
956 global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
959 $key = md5( $m . $monthnum . $year );
960 if ( $cache = wp_cache_get( 'get_calendar', 'calendar' ) ) {
961 if ( is_array($cache) && isset( $cache[ $key ] ) ) {
967 if ( !is_array($cache) )
970 // Quick check. If we have no posts at all, abort!
972 $gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1");
975 wp_cache_set( 'get_calendar', $cache, 'calendar' );
981 if ( isset($_GET['w']) )
982 $w = ''.intval($_GET['w']);
984 // week_begins = 0 stands for Sunday
985 $week_begins = intval(get_option('start_of_week'));
987 // Let's figure out when we are
988 if ( !empty($monthnum) && !empty($year) ) {
989 $thismonth = ''.zeroise(intval($monthnum), 2);
990 $thisyear = ''.intval($year);
991 } elseif ( !empty($w) ) {
992 // We need to get the month from MySQL
993 $thisyear = ''.intval(substr($m, 0, 4));
994 $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's
995 $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('${thisyear}0101', INTERVAL $d DAY) ), '%m')");
996 } elseif ( !empty($m) ) {
997 $thisyear = ''.intval(substr($m, 0, 4));
998 if ( strlen($m) < 6 )
1001 $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2);
1003 $thisyear = gmdate('Y', current_time('timestamp'));
1004 $thismonth = gmdate('m', current_time('timestamp'));
1007 $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear);
1009 // Get the next and previous month and year with at least one post
1010 $previous = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
1012 WHERE post_date < '$thisyear-$thismonth-01'
1013 AND post_type = 'post' AND post_status = 'publish'
1014 ORDER BY post_date DESC
1016 $next = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
1018 WHERE post_date > '$thisyear-$thismonth-01'
1019 AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' )
1020 AND post_type = 'post' AND post_status = 'publish'
1021 ORDER BY post_date ASC
1024 /* translators: Calendar caption: 1: month name, 2: 4-digit year */
1025 $calendar_caption = _x('%1$s %2$s', 'calendar caption');
1026 echo '<table id="wp-calendar" summary="' . esc_attr__('Calendar') . '">
1027 <caption>' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption>
1033 for ( $wdcount=0; $wdcount<=6; $wdcount++ ) {
1034 $myweek[] = $wp_locale->get_weekday(($wdcount+$week_begins)%7);
1037 foreach ( $myweek as $wd ) {
1038 $day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd);
1039 $wd = esc_attr($wd);
1040 echo "\n\t\t<th abbr=\"$wd\" scope=\"col\" title=\"$wd\">$day_name</th>";
1051 echo "\n\t\t".'<td abbr="' . $wp_locale->get_month($previous->month) . '" colspan="3" id="prev"><a href="' .
1052 get_month_link($previous->year, $previous->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($previous->month),
1053 date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year))) . '">« ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
1055 echo "\n\t\t".'<td colspan="3" id="prev" class="pad"> </td>';
1058 echo "\n\t\t".'<td class="pad"> </td>';
1061 echo "\n\t\t".'<td abbr="' . $wp_locale->get_month($next->month) . '" colspan="3" id="next"><a href="' .
1062 get_month_link($next->year, $next->month) . '" title="' . esc_attr( sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($next->month) ,
1063 date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) ) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' »</a></td>';
1065 echo "\n\t\t".'<td colspan="3" id="next" class="pad"> </td>';
1075 // Get days with posts
1076 $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
1077 FROM $wpdb->posts WHERE MONTH(post_date) = '$thismonth'
1078 AND YEAR(post_date) = '$thisyear'
1079 AND post_type = 'post' AND post_status = 'publish'
1080 AND post_date < '" . current_time('mysql') . '\'', ARRAY_N);
1081 if ( $dayswithposts ) {
1082 foreach ( (array) $dayswithposts as $daywith ) {
1083 $daywithpost[] = $daywith[0];
1086 $daywithpost = array();
1089 if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'camino') !== false || strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'safari') !== false)
1090 $ak_title_separator = "\n";
1092 $ak_title_separator = ', ';
1094 $ak_titles_for_day = array();
1095 $ak_post_titles = $wpdb->get_results("SELECT post_title, DAYOFMONTH(post_date) as dom "
1096 ."FROM $wpdb->posts "
1097 ."WHERE YEAR(post_date) = '$thisyear' "
1098 ."AND MONTH(post_date) = '$thismonth' "
1099 ."AND post_date < '".current_time('mysql')."' "
1100 ."AND post_type = 'post' AND post_status = 'publish'"
1102 if ( $ak_post_titles ) {
1103 foreach ( (array) $ak_post_titles as $ak_post_title ) {
1105 $post_title = esc_attr( apply_filters( 'the_title', $ak_post_title->post_title ) );
1107 if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) )
1108 $ak_titles_for_day['day_'.$ak_post_title->dom] = '';
1109 if ( empty($ak_titles_for_day["$ak_post_title->dom"]) ) // first one
1110 $ak_titles_for_day["$ak_post_title->dom"] = $post_title;
1112 $ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . $post_title;
1117 // See how much we should pad in the beginning
1118 $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins);
1120 echo "\n\t\t".'<td colspan="'. esc_attr($pad) .'" class="pad"> </td>';
1122 $daysinmonth = intval(date('t', $unixmonth));
1123 for ( $day = 1; $day <= $daysinmonth; ++$day ) {
1124 if ( isset($newrow) && $newrow )
1125 echo "\n\t</tr>\n\t<tr>\n\t\t";
1128 if ( $day == gmdate('j', (time() + (get_option('gmt_offset') * 3600))) && $thismonth == gmdate('m', time()+(get_option('gmt_offset') * 3600)) && $thisyear == gmdate('Y', time()+(get_option('gmt_offset') * 3600)) )
1129 echo '<td id="today">';
1133 if ( in_array($day, $daywithpost) ) // any posts today?
1134 echo '<a href="' . get_day_link($thisyear, $thismonth, $day) . "\" title=\"" . esc_attr($ak_titles_for_day[$day]) . "\">$day</a>";
1139 if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) )
1143 $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
1144 if ( $pad != 0 && $pad != 7 )
1145 echo "\n\t\t".'<td class="pad" colspan="'. esc_attr($pad) .'"> </td>';
1147 echo "\n\t</tr>\n\t</tbody>\n\t</table>";
1149 $output = ob_get_contents();
1152 $cache[ $key ] = $output;
1153 wp_cache_set( 'get_calendar', $cache, 'calendar' );
1157 * Purge the cached results of get_calendar.
1162 function delete_get_calendar_cache() {
1163 wp_cache_delete( 'get_calendar', 'calendar' );
1165 add_action( 'save_post', 'delete_get_calendar_cache' );
1166 add_action( 'delete_post', 'delete_get_calendar_cache' );
1167 add_action( 'update_option_start_of_week', 'delete_get_calendar_cache' );
1168 add_action( 'update_option_gmt_offset', 'delete_get_calendar_cache' );
1169 add_action( 'update_option_start_of_week', 'delete_get_calendar_cache' );
1172 * Display all of the allowed tags in HTML format with attributes.
1174 * This is useful for displaying in the comment area, which elements and
1175 * attributes are supported. As well as any plugins which want to display it.
1178 * @uses $allowedtags
1180 * @return string HTML allowed tags entity encoded.
1182 function allowed_tags() {
1183 global $allowedtags;
1185 foreach ( (array) $allowedtags as $tag => $attributes ) {
1186 $allowed .= '<'.$tag;
1187 if ( 0 < count($attributes) ) {
1188 foreach ( $attributes as $attribute => $limits ) {
1189 $allowed .= ' '.$attribute.'=""';
1194 return htmlentities($allowed);
1197 /***** Date/Time tags *****/
1200 * Outputs the date in iso8601 format for xml files.
1204 function the_date_xml() {
1206 echo mysql2date('Y-m-d', $post->post_date, false);
1210 * Display or Retrieve the date the post was written.
1212 * Will only output the date if the current post's date is different from the
1213 * previous one output.
1217 * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
1218 * @param string $before Optional. Output before the date.
1219 * @param string $after Optional. Output after the date.
1220 * @param bool $echo Optional, default is display. Whether to echo the date or return it.
1221 * @return string|null Null if displaying, string if retrieving.
1223 function the_date($d='', $before='', $after='', $echo = true) {
1224 global $post, $day, $previousday;
1226 if ( $day != $previousday ) {
1227 $the_date .= $before;
1229 $the_date .= mysql2date(get_option('date_format'), $post->post_date);
1231 $the_date .= mysql2date($d, $post->post_date);
1232 $the_date .= $after;
1233 $previousday = $day;
1235 $the_date = apply_filters('the_date', $the_date, $d, $before, $after);
1244 * Display the date on which the post was last modified.
1248 * @param string $d Optional. PHP date format.
1251 function the_modified_date($d = '') {
1252 echo apply_filters('the_modified_date', get_the_modified_date($d), $d);
1256 * Retrieve the date on which the post was last modified.
1260 * @param string $d Optional. PHP date format. Defaults to the "date_format" option
1263 function get_the_modified_date($d = '') {
1265 $the_time = get_post_modified_time(get_option('date_format'), null, null, true);
1267 $the_time = get_post_modified_time($d, null, null, true);
1268 return apply_filters('get_the_modified_date', $the_time, $d);
1272 * Display the time at which the post was written.
1276 * @param string $d Either 'G', 'U', or php date format.
1278 function the_time( $d = '' ) {
1279 echo apply_filters('the_time', get_the_time( $d ), $d);
1283 * Retrieve the time at which the post was written.
1287 * @param string $d Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
1288 * @param int|object $post Optional post ID or object. Default is global $post object.
1291 function get_the_time( $d = '', $post = null ) {
1292 $post = get_post($post);
1295 $the_time = get_post_time(get_option('time_format'), false, $post, true);
1297 $the_time = get_post_time($d, false, $post, true);
1298 return apply_filters('get_the_time', $the_time, $d, $post);
1302 * Retrieve the time at which the post was written.
1306 * @param string $d Either 'G', 'U', or php date format.
1307 * @param bool $gmt Whether of not to return the gmt time.
1308 * @param int|object $post Optional post ID or object. Default is global $post object.
1309 * @param bool $translate Whether to translate the time string or not
1312 function get_post_time( $d = 'U', $gmt = false, $post = null, $translate = false ) { // returns timestamp
1313 $post = get_post($post);
1316 $time = $post->post_date_gmt;
1318 $time = $post->post_date;
1320 $time = mysql2date($d, $time, $translate);
1321 return apply_filters('get_post_time', $time, $d, $gmt);
1325 * Display the time at which the post was last modified.
1329 * @param string $d Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
1331 function the_modified_time($d = '') {
1332 echo apply_filters('the_modified_time', get_the_modified_time($d), $d);
1336 * Retrieve the time at which the post was last modified.
1340 * @param string $d Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
1343 function get_the_modified_time($d = '') {
1345 $the_time = get_post_modified_time(get_option('time_format'), null, null, true);
1347 $the_time = get_post_modified_time($d, null, null, true);
1348 return apply_filters('get_the_modified_time', $the_time, $d);
1352 * Retrieve the time at which the post was last modified.
1356 * @param string $d Either 'G', 'U', or php date format.
1357 * @param bool $gmt Whether of not to return the gmt time.
1358 * @param int|object $post A post_id or post object
1359 * @param bool translate Whether to translate the result or not
1360 * @return string Returns timestamp
1362 function get_post_modified_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
1363 $post = get_post($post);
1366 $time = $post->post_modified_gmt;
1368 $time = $post->post_modified;
1369 $time = mysql2date($d, $time, $translate);
1371 return apply_filters('get_post_modified_time', $time, $d, $gmt);
1375 * Display the weekday on which the post was written.
1381 function the_weekday() {
1382 global $wp_locale, $post;
1383 $the_weekday = $wp_locale->get_weekday(mysql2date('w', $post->post_date, false));
1384 $the_weekday = apply_filters('the_weekday', $the_weekday);
1389 * Display the weekday on which the post was written.
1391 * Will only output the weekday if the current post's weekday is different from
1392 * the previous one output.
1396 * @param string $before output before the date.
1397 * @param string $after output after the date.
1399 function the_weekday_date($before='',$after='') {
1400 global $wp_locale, $post, $day, $previousweekday;
1401 $the_weekday_date = '';
1402 if ( $day != $previousweekday ) {
1403 $the_weekday_date .= $before;
1404 $the_weekday_date .= $wp_locale->get_weekday(mysql2date('w', $post->post_date, false));
1405 $the_weekday_date .= $after;
1406 $previousweekday = $day;
1408 $the_weekday_date = apply_filters('the_weekday_date', $the_weekday_date, $before, $after);
1409 echo $the_weekday_date;
1413 * Fire the wp_head action
1416 * @uses do_action() Calls 'wp_head' hook.
1418 function wp_head() {
1419 do_action('wp_head');
1423 * Fire the wp_footer action
1426 * @uses do_action() Calls 'wp_footer' hook.
1428 function wp_footer() {
1429 do_action('wp_footer');
1433 * Enable/disable automatic general feed link outputting.
1437 * @param boolean $add Add or remove links. Defaults to true.
1439 function automatic_feed_links( $add = true ) {
1441 add_action( 'wp_head', 'feed_links', 2 );
1443 remove_action( 'wp_head', 'feed_links', 2 );
1444 remove_action( 'wp_head', 'feed_links_extra', 3 );
1449 * Display the links to the general feeds.
1453 * @param array $args Optional arguments.
1455 function feed_links( $args ) {
1457 /* translators: Separator between blog name and feed type in feed links */
1458 'separator' => _x('»', 'feed link'),
1459 /* translators: 1: blog title, 2: separator (raquo) */
1460 'feedtitle' => __('%1$s %2$s Feed'),
1461 /* translators: %s: blog title, 2: separator (raquo) */
1462 'comstitle' => __('%1$s %2$s Comments Feed'),
1465 $args = wp_parse_args( $args, $defaults );
1467 echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr(sprintf( $args['feedtitle'], get_bloginfo('name'), $args['separator'] )) . '" href="' . get_feed_link() . "\" />\n";
1468 echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . esc_attr(sprintf( $args['comstitle'], get_bloginfo('name'), $args['separator'] )) . '" href="' . get_feed_link( 'comments_' . get_default_feed() ) . "\" />\n";
1472 * Display the links to the extra feeds such as category feeds.
1476 * @param array $args Optional arguments.
1478 function feed_links_extra( $args ) {
1480 /* translators: Separator between blog name and feed type in feed links */
1481 'separator' => _x('»', 'feed link'),
1482 /* translators: 1: blog name, 2: separator(raquo), 3: post title */
1483 'singletitle' => __('%1$s %2$s %3$s Comments Feed'),
1484 /* translators: 1: blog name, 2: separator(raquo), 3: category name */
1485 'cattitle' => __('%1$s %2$s %3$s Category Feed'),
1486 /* translators: 1: blog name, 2: separator(raquo), 3: tag name */
1487 'tagtitle' => __('%1$s %2$s %3$s Tag Feed'),
1488 /* translators: 1: blog name, 2: separator(raquo), 3: author name */
1489 'authortitle' => __('%1$s %2$s Posts by %3$s Feed'),
1490 /* translators: 1: blog name, 2: separator(raquo), 3: search phrase */
1491 'searchtitle' => __('%1$s %2$s Search Results for “%3$s” Feed'),
1494 $args = wp_parse_args( $args, $defaults );
1496 if ( is_single() || is_page() ) {
1497 $post = &get_post( $id = 0 );
1499 if ( comments_open() || pings_open() || $post->comment_count > 0 ) {
1500 $title = esc_attr(sprintf( $args['singletitle'], get_bloginfo('name'), $args['separator'], esc_html( get_the_title() ) ));
1501 $href = get_post_comments_feed_link( $post->ID );
1503 } elseif ( is_category() ) {
1504 $cat_id = intval( get_query_var('cat') );
1506 $title = esc_attr(sprintf( $args['cattitle'], get_bloginfo('name'), $args['separator'], get_cat_name( $cat_id ) ));
1507 $href = get_category_feed_link( $cat_id );
1508 } elseif ( is_tag() ) {
1509 $tag_id = intval( get_query_var('tag_id') );
1510 $tag = get_tag( $tag_id );
1512 $title = esc_attr(sprintf( $args['tagtitle'], get_bloginfo('name'), $args['separator'], $tag->name ));
1513 $href = get_tag_feed_link( $tag_id );
1514 } elseif ( is_author() ) {
1515 $author_id = intval( get_query_var('author') );
1517 $title = esc_attr(sprintf( $args['authortitle'], get_bloginfo('name'), $args['separator'], get_the_author_meta( 'display_name', $author_id ) ));
1518 $href = get_author_feed_link( $author_id );
1519 } elseif ( is_search() ) {
1520 $title = esc_attr(sprintf( $args['searchtitle'], get_bloginfo('name'), $args['separator'], get_search_query() ));
1521 $href = get_search_feed_link();
1524 if ( isset($title) && isset($href) )
1525 echo '<link rel="alternate" type="' . feed_content_type() . '" title="' . $title . '" href="' . $href . '" />' . "\n";
1529 * Display the link to the Really Simple Discovery service endpoint.
1531 * @link http://archipelago.phrasewise.com/rsd
1534 function rsd_link() {
1535 echo '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . get_bloginfo('wpurl') . "/xmlrpc.php?rsd\" />\n";
1539 * Display the link to the Windows Live Writer manifest file.
1541 * @link http://msdn.microsoft.com/en-us/library/bb463265.aspx
1544 function wlwmanifest_link() {
1545 echo '<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="'
1546 . get_bloginfo('wpurl') . '/wp-includes/wlwmanifest.xml" /> ' . "\n";
1550 * Display a noindex meta tag if required by the blog configuration.
1552 * If a blog is marked as not being public then the noindex meta tag will be
1553 * output to tell web robots not to index the page content.
1557 function noindex() {
1558 // If the blog is not public, tell robots to go away.
1559 if ( '0' == get_option('blog_public') )
1560 echo "<meta name='robots' content='noindex,nofollow' />\n";
1564 * Determine if TinyMCE is available.
1566 * Checks to see if the user has deleted the tinymce files to slim down there WordPress install.
1570 * @return bool Whether of not TinyMCE exists.
1572 function rich_edit_exists() {
1573 global $wp_rich_edit_exists;
1574 if ( !isset($wp_rich_edit_exists) )
1575 $wp_rich_edit_exists = file_exists(ABSPATH . WPINC . '/js/tinymce/tiny_mce.js');
1576 return $wp_rich_edit_exists;
1580 * Whether or not the user should have a WYSIWIG editor.
1582 * Checks that the user requires a WYSIWIG editor and that the editor is
1583 * supported in the users browser.
1589 function user_can_richedit() {
1590 global $wp_rich_edit, $pagenow;
1592 if ( !isset( $wp_rich_edit) ) {
1593 if ( get_user_option( 'rich_editing' ) == 'true' &&
1594 ( ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && intval($match[1]) >= 420 ) ||
1595 !preg_match( '!opera[ /][2-8]|konqueror|safari!i', $_SERVER['HTTP_USER_AGENT'] ) )
1596 && 'comment.php' != $pagenow ) {
1597 $wp_rich_edit = true;
1599 $wp_rich_edit = false;
1603 return apply_filters('user_can_richedit', $wp_rich_edit);
1607 * Find out which editor should be displayed by default.
1609 * Works out which of the two editors to display as the current editor for a
1614 * @return string Either 'tinymce', or 'html', or 'test'
1616 function wp_default_editor() {
1617 $r = user_can_richedit() ? 'tinymce' : 'html'; // defaults
1618 if ( $user = wp_get_current_user() ) { // look for cookie
1619 $ed = get_user_setting('editor', 'tinymce');
1620 $r = ( in_array($ed, array('tinymce', 'html', 'test') ) ) ? $ed : $r;
1622 return apply_filters( 'wp_default_editor', $r ); // filter
1626 * Display visual editor forms: TinyMCE, or HTML, or both.
1628 * The amount of rows the text area will have for the content has to be between
1629 * 3 and 100 or will default at 12. There is only one option used for all users,
1630 * named 'default_post_edit_rows'.
1632 * If the user can not use the rich editor (TinyMCE), then the switch button
1633 * will not be displayed.
1637 * @param string $content Textarea content.
1638 * @param string $id HTML ID attribute value.
1639 * @param string $prev_id HTML ID name for switching back and forth between visual editors.
1640 * @param bool $media_buttons Optional, default is true. Whether to display media buttons.
1641 * @param int $tab_index Optional, default is 2. Tabindex for textarea element.
1643 function the_editor($content, $id = 'content', $prev_id = 'title', $media_buttons = true, $tab_index = 2) {
1644 $rows = get_option('default_post_edit_rows');
1645 if (($rows < 3) || ($rows > 100))
1648 if ( !current_user_can( 'upload_files' ) )
1649 $media_buttons = false;
1651 $richedit = user_can_richedit();
1654 if ( $richedit || $media_buttons ) { ?>
1655 <div id="editor-toolbar">
1658 $wp_default_editor = wp_default_editor(); ?>
1659 <div class="zerosize"><input accesskey="e" type="button" onclick="switchEditors.go('<?php echo $id; ?>')" /></div>
1660 <?php if ( 'html' == $wp_default_editor ) {
1661 add_filter('the_editor_content', 'wp_htmledit_pre'); ?>
1662 <a id="edButtonHTML" class="active hide-if-no-js" onclick="switchEditors.go('<?php echo $id; ?>', 'html');"><?php _e('HTML'); ?></a>
1663 <a id="edButtonPreview" class="hide-if-no-js" onclick="switchEditors.go('<?php echo $id; ?>', 'tinymce');"><?php _e('Visual'); ?></a>
1665 $class = " class='theEditor'";
1666 add_filter('the_editor_content', 'wp_richedit_pre'); ?>
1667 <a id="edButtonHTML" class="hide-if-no-js" onclick="switchEditors.go('<?php echo $id; ?>', 'html');"><?php _e('HTML'); ?></a>
1668 <a id="edButtonPreview" class="active hide-if-no-js" onclick="switchEditors.go('<?php echo $id; ?>', 'tinymce');"><?php _e('Visual'); ?></a>
1672 if ( $media_buttons ) { ?>
1673 <div id="media-buttons" class="hide-if-no-js">
1674 <?php do_action( 'media_buttons' ); ?>
1682 <div id="quicktags"><?php
1683 wp_print_scripts( 'quicktags' ); ?>
1684 <script type="text/javascript">edToolbar()</script>
1688 $the_editor = apply_filters('the_editor', "<div id='editorcontainer'><textarea rows='$rows'$class cols='40' name='$id' tabindex='$tab_index' id='$id'>%s</textarea></div>\n");
1689 $the_editor_content = apply_filters('the_editor_content', $content);
1691 printf($the_editor, $the_editor_content);
1694 <script type="text/javascript">
1695 edCanvas = document.getElementById('<?php echo $id; ?>');
1701 * Retrieve the contents of the search WordPress query variable.
1707 function get_search_query() {
1708 return apply_filters( 'get_search_query', stripslashes( get_query_var( 's' ) ) );
1712 * Display the contents of the search query variable.
1714 * The search query string is passed through {@link esc_attr()}
1715 * to ensure that it is safe for placing in an html attribute.
1720 function the_search_query() {
1721 echo esc_attr( apply_filters( 'the_search_query', get_search_query() ) );
1725 * Display the language attributes for the html tag.
1727 * Builds up a set of html attributes containing the text direction and language
1728 * information for the page.
1732 * @param string $doctype The type of html document (xhtml|html).
1734 function language_attributes($doctype = 'html') {
1735 $attributes = array();
1738 if ( $dir = get_bloginfo('text_direction') )
1739 $attributes[] = "dir=\"$dir\"";
1741 if ( $lang = get_bloginfo('language') ) {
1742 if ( get_option('html_type') == 'text/html' || $doctype == 'html' )
1743 $attributes[] = "lang=\"$lang\"";
1745 if ( get_option('html_type') != 'text/html' || $doctype == 'xhtml' )
1746 $attributes[] = "xml:lang=\"$lang\"";
1749 $output = implode(' ', $attributes);
1750 $output = apply_filters('language_attributes', $output);
1755 * Retrieve paginated link for archive post pages.
1757 * Technically, the function can be used to create paginated link list for any
1758 * area. The 'base' argument is used to reference the url, which will be used to
1759 * create the paginated links. The 'format' argument is then used for replacing
1760 * the page number. It is however, most likely and by default, to be used on the
1761 * archive post pages.
1763 * The 'type' argument controls format of the returned value. The default is
1764 * 'plain', which is just a string with the links separated by a newline
1765 * character. The other possible values are either 'array' or 'list'. The
1766 * 'array' value will return an array of the paginated link list to offer full
1767 * control of display. The 'list' value will place all of the paginated links in
1768 * an unordered HTML list.
1770 * The 'total' argument is the total amount of pages and is an integer. The
1771 * 'current' argument is the current page number and is also an integer.
1773 * An example of the 'base' argument is "http://example.com/all_posts.php%_%"
1774 * and the '%_%' is required. The '%_%' will be replaced by the contents of in
1775 * the 'format' argument. An example for the 'format' argument is "?page=%#%"
1776 * and the '%#%' is also required. The '%#%' will be replaced with the page
1779 * You can include the previous and next links in the list by setting the
1780 * 'prev_next' argument to true, which it is by default. You can set the
1781 * previous text, by using the 'prev_text' argument. You can set the next text
1782 * by setting the 'next_text' argument.
1784 * If the 'show_all' argument is set to true, then it will show all of the pages
1785 * instead of a short list of the pages near the current page. By default, the
1786 * 'show_all' is set to false and controlled by the 'end_size' and 'mid_size'
1787 * arguments. The 'end_size' argument is how many numbers on either the start
1788 * and the end list edges, by default is 1. The 'mid_size' argument is how many
1789 * numbers to either side of current page, but not including current page.
1791 * It is possible to add query vars to the link by using the 'add_args' argument
1792 * and see {@link add_query_arg()} for more information.
1796 * @param string|array $args Optional. Override defaults.
1797 * @return array|string String of page links or array of page links.
1799 function paginate_links( $args = '' ) {
1801 'base' => '%_%', // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
1802 'format' => '?page=%#%', // ?page=%#% : %#% is replaced by the page number
1805 'show_all' => false,
1806 'prev_next' => true,
1807 'prev_text' => __('« Previous'),
1808 'next_text' => __('Next »'),
1812 'add_args' => false, // array of query args to add
1813 'add_fragment' => ''
1816 $args = wp_parse_args( $args, $defaults );
1817 extract($args, EXTR_SKIP);
1819 // Who knows what else people pass in $args
1820 $total = (int) $total;
1823 $current = (int) $current;
1824 $end_size = 0 < (int) $end_size ? (int) $end_size : 1; // Out of bounds? Make it the default.
1825 $mid_size = 0 <= (int) $mid_size ? (int) $mid_size : 2;
1826 $add_args = is_array($add_args) ? $add_args : false;
1828 $page_links = array();
1832 if ( $prev_next && $current && 1 < $current ) :
1833 $link = str_replace('%_%', 2 == $current ? '' : $format, $base);
1834 $link = str_replace('%#%', $current - 1, $link);
1836 $link = add_query_arg( $add_args, $link );
1837 $link .= $add_fragment;
1838 $page_links[] = "<a class='prev page-numbers' href='" . esc_url($link) . "'>$prev_text</a>";
1840 for ( $n = 1; $n <= $total; $n++ ) :
1841 $n_display = number_format_i18n($n);
1842 if ( $n == $current ) :
1843 $page_links[] = "<span class='page-numbers current'>$n_display</span>";
1846 if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
1847 $link = str_replace('%_%', 1 == $n ? '' : $format, $base);
1848 $link = str_replace('%#%', $n, $link);
1850 $link = add_query_arg( $add_args, $link );
1851 $link .= $add_fragment;
1852 $page_links[] = "<a class='page-numbers' href='" . esc_url($link) . "'>$n_display</a>";
1854 elseif ( $dots && !$show_all ) :
1855 $page_links[] = "<span class='page-numbers dots'>...</span>";
1860 if ( $prev_next && $current && ( $current < $total || -1 == $total ) ) :
1861 $link = str_replace('%_%', $format, $base);
1862 $link = str_replace('%#%', $current + 1, $link);
1864 $link = add_query_arg( $add_args, $link );
1865 $link .= $add_fragment;
1866 $page_links[] = "<a class='next page-numbers' href='" . esc_url($link) . "'>$next_text</a>";
1873 $r .= "<ul class='page-numbers'>\n\t<li>";
1874 $r .= join("</li>\n\t<li>", $page_links);
1875 $r .= "</li>\n</ul>\n";
1878 $r = join("\n", $page_links);
1885 * Registers an admin colour scheme css file.
1887 * Allows a plugin to register a new admin colour scheme. For example:
1889 * wp_admin_css_color('classic', __('Classic'), admin_url("css/colors-classic.css"),
1890 * array('#07273E', '#14568A', '#D54E21', '#2683AE'));
1895 * @param string $key The unique key for this theme.
1896 * @param string $name The name of the theme.
1897 * @param string $url The url of the css file containing the colour scheme.
1898 * @param array @colors An array of CSS color definitions which are used to give the user a feel for the theme.
1900 function wp_admin_css_color($key, $name, $url, $colors = array()) {
1901 global $_wp_admin_css_colors;
1903 if ( !isset($_wp_admin_css_colors) )
1904 $_wp_admin_css_colors = array();
1906 $_wp_admin_css_colors[$key] = (object) array('name' => $name, 'url' => $url, 'colors' => $colors);
1910 * Display the URL of a WordPress admin CSS file.
1912 * @see WP_Styles::_css_href and its style_loader_src filter.
1916 * @param string $file file relative to wp-admin/ without its ".css" extension.
1918 function wp_admin_css_uri( $file = 'wp-admin' ) {
1919 if ( defined('WP_INSTALLING') ) {
1920 $_file = "./$file.css";
1922 $_file = admin_url("$file.css");
1924 $_file = add_query_arg( 'version', get_bloginfo( 'version' ), $_file );
1926 return apply_filters( 'wp_admin_css_uri', $_file, $file );
1930 * Enqueues or directly prints a stylesheet link to the specified CSS file.
1932 * "Intelligently" decides to enqueue or to print the CSS file. If the
1933 * 'wp_print_styles' action has *not* yet been called, the CSS file will be
1934 * enqueued. If the wp_print_styles action *has* been called, the CSS link will
1935 * be printed. Printing may be forced by passing TRUE as the $force_echo
1936 * (second) parameter.
1938 * For backward compatibility with WordPress 2.3 calling method: If the $file
1939 * (first) parameter does not correspond to a registered CSS file, we assume
1940 * $file is a file relative to wp-admin/ without its ".css" extension. A
1941 * stylesheet link to that generated URL is printed.
1943 * @package WordPress
1945 * @uses $wp_styles WordPress Styles Object
1947 * @param string $file Style handle name or file name (without ".css" extension) relative to wp-admin/
1948 * @param bool $force_echo Optional. Force the stylesheet link to be printed rather than enqueued.
1950 function wp_admin_css( $file = 'wp-admin', $force_echo = false ) {
1952 if ( !is_a($wp_styles, 'WP_Styles') )
1953 $wp_styles = new WP_Styles();
1955 // For backward compatibility
1956 $handle = 0 === strpos( $file, 'css/' ) ? substr( $file, 4 ) : $file;
1958 if ( $wp_styles->query( $handle ) ) {
1959 if ( $force_echo || did_action( 'wp_print_styles' ) ) // we already printed the style queue. Print this one immediately
1960 wp_print_styles( $handle );
1961 else // Add to style queue
1962 wp_enqueue_style( $handle );
1966 echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( $file ) ) . "' type='text/css' />\n", $file );
1967 if ( 'rtl' == get_bloginfo( 'text_direction' ) )
1968 echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . esc_url( wp_admin_css_uri( "$file-rtl" ) ) . "' type='text/css' />\n", "$file-rtl" );
1972 * Enqueues the default ThickBox js and css.
1974 * If any of the settings need to be changed, this can be done with another js
1975 * file similar to media-upload.js and theme-preview.js. That file should
1976 * require array('thickbox') to ensure it is loaded after.
1980 function add_thickbox() {
1981 wp_enqueue_script( 'thickbox' );
1982 wp_enqueue_style( 'thickbox' );
1986 * Display the XHTML generator that is generated on the wp_head hook.
1990 function wp_generator() {
1991 the_generator( apply_filters( 'wp_generator_type', 'xhtml' ) );
1995 * Display the generator XML or Comment for RSS, ATOM, etc.
1997 * Returns the correct generator type for the requested output format. Allows
1998 * for a plugin to filter generators overall the the_generator filter.
2001 * @uses apply_filters() Calls 'the_generator' hook.
2003 * @param string $type The type of generator to output - (html|xhtml|atom|rss2|rdf|comment|export).
2005 function the_generator( $type ) {
2006 echo apply_filters('the_generator', get_the_generator($type), $type) . "\n";
2010 * Creates the generator XML or Comment for RSS, ATOM, etc.
2012 * Returns the correct generator type for the requested output format. Allows
2013 * for a plugin to filter generators on an individual basis using the
2014 * 'get_the_generator_{$type}' filter.
2017 * @uses apply_filters() Calls 'get_the_generator_$type' hook.
2019 * @param string $type The type of generator to return - (html|xhtml|atom|rss2|rdf|comment|export).
2020 * @return string The HTML content for the generator.
2022 function get_the_generator( $type ) {
2025 $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '">';
2028 $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '" />';
2031 $gen = '<generator uri="http://wordpress.org/" version="' . get_bloginfo_rss( 'version' ) . '">WordPress</generator>';
2034 $gen = '<generator>http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '</generator>';
2037 $gen = '<admin:generatorAgent rdf:resource="http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '" />';
2040 $gen = '<!-- generator="WordPress/' . get_bloginfo( 'version' ) . '" -->';
2043 $gen = '<!-- generator="WordPress/' . get_bloginfo_rss('version') . '" created="'. date('Y-m-d H:i') . '"-->';
2046 return apply_filters( "get_the_generator_{$type}", $gen, $type );