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' );
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' );
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' );
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
105 function get_search_form() {
106 do_action( 'get_search_form' );
108 if ( '' != locate_template(array('searchform.php'), true) )
111 $form = '<form method="get" id="searchform" action="' . get_option('home') . '/" >
112 <label class="hidden" for="s">' . __('Search for:') . '</label>
113 <div><input type="text" value="' . attribute_escape(apply_filters('the_search_query', get_search_query())) . '" name="s" id="s" />
114 <input type="submit" id="searchsubmit" value="'.attribute_escape(__('Search')).'" />
118 echo apply_filters('get_search_form', $form);
122 * Display the Log In/Out link.
124 * Displays a link, which allows the user to navigate to the Log In page to log in
125 * or log out depending on whether or not they are currently logged in.
128 * @uses apply_filters() Calls 'loginout' hook on HTML link content.
130 function wp_loginout() {
131 if ( ! is_user_logged_in() )
132 $link = '<a href="' . wp_login_url() . '">' . __('Log in') . '</a>';
134 $link = '<a href="' . wp_logout_url() . '">' . __('Log out') . '</a>';
136 echo apply_filters('loginout', $link);
140 * Returns the Log Out URL.
142 * Returns the URL that allows the user to log out of the site
145 * @uses wp_nonce_url() To protect against CSRF
146 * @uses site_url() To generate the log in URL
148 * @param string $redirect Path to redirect to on logout.
150 function wp_logout_url($redirect = '') {
151 if ( strlen($redirect) )
152 $redirect = "&redirect_to=$redirect";
154 return wp_nonce_url( site_url("wp-login.php?action=logout$redirect", 'login'), 'log-out' );
158 * Returns the Log In URL.
160 * Returns the URL that allows the user to log in to the site
163 * @uses site_url() To generate the log in URL
165 * @param string $redirect Path to redirect to on login.
167 function wp_login_url($redirect = '') {
168 if ( strlen($redirect) )
169 $redirect = "?redirect_to=$redirect";
171 return site_url("wp-login.php$redirect", 'login');
175 * Display the Registration or Admin link.
177 * Display a link which allows the user to navigate to the registration page if
178 * not logged in and registration is enabled or to the dashboard if logged in.
181 * @uses apply_filters() Calls 'register' hook on register / admin link content.
183 * @param string $before Text to output before the link (defaults to <li>).
184 * @param string $after Text to output after the link (defaults to </li>).
186 function wp_register( $before = '<li>', $after = '</li>' ) {
188 if ( ! is_user_logged_in() ) {
189 if ( get_option('users_can_register') )
190 $link = $before . '<a href="' . site_url('wp-login.php?action=register', 'login') . '">' . __('Register') . '</a>' . $after;
194 $link = $before . '<a href="' . admin_url() . '">' . __('Site Admin') . '</a>' . $after;
197 echo apply_filters('register', $link);
201 * Theme container function for the 'wp_meta' action.
203 * The 'wp_meta' action can have several purposes, depending on how you use it,
204 * but one purpose might have been to allow for theme switching.
207 * @link http://trac.wordpress.org/ticket/1458 Explanation of 'wp_meta' action.
208 * @uses do_action() Calls 'wp_meta' hook.
211 do_action('wp_meta');
215 * Display information about the blog.
217 * @see get_bloginfo() For possible values for the parameter.
220 * @param string $show What to display.
222 function bloginfo($show='') {
223 echo get_bloginfo($show, 'display');
227 * Retrieve information about the blog.
229 * Some show parameter values are deprecated and will be removed in future
230 * versions. Care should be taken to check the function contents and know what
231 * the deprecated blog info options are. Options without "// DEPRECATED" are
232 * the preferred and recommended ways to get the information.
234 * The possible values for the 'show' parameter are listed below.
236 * <li><strong>url<strong> - Blog URI to homepage.</li>
237 * <li><strong>wpurl</strong> - Blog URI path to WordPress.</li>
238 * <li><strong>description</strong> - Secondary title</li>
241 * The feed URL options can be retrieved from 'rdf_url' (RSS 0.91),
242 * 'rss_url' (RSS 1.0), 'rss2_url' (RSS 2.0), or 'atom_url' (Atom feed). The
243 * comment feeds can be retrieved from the 'comments_atom_url' (Atom comment
244 * feed) or 'comments_rss2_url' (RSS 2.0 comment feed).
246 * There are many other options and you should check the function contents:
251 * @param string $show Blog info to retrieve.
252 * @param string $filter How to filter what is retrieved.
253 * @return string Mostly string values, might be empty.
255 function get_bloginfo($show = '', $filter = 'raw') {
259 case 'home' : // DEPRECATED
260 case 'siteurl' : // DEPRECATED
261 $output = get_option('home');
264 $output = get_option('siteurl');
267 $output = get_option('blogdescription');
270 $output = get_feed_link('rdf');
273 $output = get_feed_link('rss');
276 $output = get_feed_link('rss2');
279 $output = get_feed_link('atom');
281 case 'comments_atom_url':
282 $output = get_feed_link('comments_atom');
284 case 'comments_rss2_url':
285 $output = get_feed_link('comments_rss2');
288 $output = get_option('siteurl') .'/xmlrpc.php';
290 case 'stylesheet_url':
291 $output = get_stylesheet_uri();
293 case 'stylesheet_directory':
294 $output = get_stylesheet_directory_uri();
296 case 'template_directory':
298 $output = get_template_directory_uri();
301 $output = get_option('admin_email');
304 $output = get_option('blog_charset');
305 if ('' == $output) $output = 'UTF-8';
308 $output = get_option('html_type');
312 $output = $wp_version;
315 $output = get_locale();
316 $output = str_replace('_', '-', $output);
318 case 'text_direction':
320 $output = $wp_locale->text_direction;
324 $output = get_option('blogname');
329 if (strpos($show, 'url') === false &&
330 strpos($show, 'directory') === false &&
331 strpos($show, 'home') === false)
334 if ( 'display' == $filter ) {
336 $output = apply_filters('bloginfo_url', $output, $show);
338 $output = apply_filters('bloginfo', $output, $show);
345 * Display or retrieve page title for all areas of blog.
347 * By default, the page title will display the separator before the page title,
348 * so that the blog title will be before the page title. This is not good for
349 * title display, since the blog title shows up on most tabs and not what is
350 * important, which is the page that the user is looking at.
352 * There are also SEO benefits to having the blog title after or to the 'right'
353 * or the page title. However, it is mostly common sense to have the blog title
354 * to the right with most browsers supporting tabs. You can achieve this by
355 * using the seplocation parameter and setting the value to 'right'. This change
356 * was introduced around 2.5.0, in case backwards compatibility of themes is
361 * @param string $sep Optional, default is '»'. How to separate the various items within the page title.
362 * @param bool $display Optional, default is true. Whether to display or retrieve title.
363 * @param string $seplocation Optional. Direction to display title, 'right'.
364 * @return string|null String on retrieve, null when displaying.
366 function wp_title($sep = '»', $display = true, $seplocation = '') {
367 global $wpdb, $wp_locale, $wp_query;
369 $cat = get_query_var('cat');
370 $tag = get_query_var('tag_id');
371 $category_name = get_query_var('category_name');
372 $author = get_query_var('author');
373 $author_name = get_query_var('author_name');
374 $m = get_query_var('m');
375 $year = get_query_var('year');
376 $monthnum = get_query_var('monthnum');
377 $day = get_query_var('day');
380 $t_sep = '%WP_TITILE_SEP%'; // Temporary separator, for accurate flipping, if necessary
382 // If there's a category
383 if ( !empty($cat) ) {
384 // category exclusion
385 if ( !stristr($cat,'-') )
386 $title = apply_filters('single_cat_title', get_the_category_by_ID($cat));
387 } elseif ( !empty($category_name) ) {
388 if ( stristr($category_name,'/') ) {
389 $category_name = explode('/',$category_name);
390 if ( $category_name[count($category_name)-1] )
391 $category_name = $category_name[count($category_name)-1]; // no trailing slash
393 $category_name = $category_name[count($category_name)-2]; // there was a trailling slash
395 $cat = get_term_by('slug', $category_name, 'category', OBJECT, 'display');
397 $title = apply_filters('single_cat_title', $cat->name);
400 if ( !empty($tag) ) {
401 $tag = get_term($tag, 'post_tag', OBJECT, 'display');
402 if ( is_wp_error( $tag ) )
404 if ( ! empty($tag->name) )
405 $title = apply_filters('single_tag_title', $tag->name);
408 // If there's an author
409 if ( !empty($author) ) {
410 $title = get_userdata($author);
411 $title = $title->display_name;
413 if ( !empty($author_name) ) {
414 // We do a direct query here because we don't cache by nicename.
415 $title = $wpdb->get_var($wpdb->prepare("SELECT display_name FROM $wpdb->users WHERE user_nicename = %s", $author_name));
418 // If there's a month
420 $my_year = substr($m, 0, 4);
421 $my_month = $wp_locale->get_month(substr($m, 4, 2));
422 $my_day = intval(substr($m, 6, 2));
423 $title = "$my_year" . ($my_month ? "$t_sep$my_month" : "") . ($my_day ? "$t_sep$my_day" : "");
426 if ( !empty($year) ) {
428 if ( !empty($monthnum) )
429 $title .= "$t_sep" . $wp_locale->get_month($monthnum);
431 $title .= "$t_sep" . zeroise($day, 2);
434 // If there is a post
435 if ( is_single() || ( is_page() && !is_front_page() ) ) {
436 $post = $wp_query->get_queried_object();
437 $title = strip_tags( apply_filters( 'single_post_title', $post->post_title ) );
440 // If there's a taxonomy
442 $taxonomy = get_query_var( 'taxonomy' );
443 $tax = get_taxonomy( $taxonomy );
445 $term = $wp_query->get_queried_object();
447 $title = "$tax$t_sep$term";
451 $title = __('Page not found');
455 if ( !empty($title) )
458 // Determines position of the separator and direction of the breadcrumb
459 if ( 'right' == $seplocation ) { // sep on right, so reverse the order
460 $title_array = explode( $t_sep, $title );
461 $title_array = array_reverse( $title_array );
462 $title = implode( " $sep ", $title_array ) . $prefix;
464 $title_array = explode( $t_sep, $title );
465 $title = $prefix . implode( " $sep ", $title_array );
468 $title = apply_filters('wp_title', $title, $sep, $seplocation);
479 * Display or retrieve page title for post.
481 * This is optimized for single.php template file for displaying the post title.
482 * Only useful for posts, does not support pages for example.
484 * It does not support placing the separator after the title, but by leaving the
485 * prefix parameter empty, you can set the title separator manually. The prefix
486 * does not automatically place a space between the prefix, so if there should
487 * be a space, the parameter value will need to have it at the end.
492 * @param string $prefix Optional. What to display before the title.
493 * @param bool $display Optional, default is true. Whether to display or retrieve title.
494 * @return string|null Title when retrieving, null when displaying or failure.
496 function single_post_title($prefix = '', $display = true) {
498 $p = get_query_var('p');
499 $name = get_query_var('name');
501 if ( intval($p) || '' != $name ) {
503 $p = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_name = %s", $name));
504 $post = & get_post($p);
505 $title = $post->post_title;
506 $title = apply_filters('single_post_title', $title);
508 echo $prefix.strip_tags($title);
510 return strip_tags($title);
515 * Display or retrieve page title for category archive.
517 * This is useful for category template file or files, because it is optimized
518 * for category page title and with less overhead than {@link wp_title()}.
520 * It does not support placing the separator after the title, but by leaving the
521 * prefix parameter empty, you can set the title separator manually. The prefix
522 * does not automatically place a space between the prefix, so if there should
523 * be a space, the parameter value will need to have it at the end.
527 * @param string $prefix Optional. What to display before the title.
528 * @param bool $display Optional, default is true. Whether to display or retrieve title.
529 * @return string|null Title when retrieving, null when displaying or failure.
531 function single_cat_title($prefix = '', $display = true ) {
532 $cat = intval( get_query_var('cat') );
533 if ( !empty($cat) && !(strtoupper($cat) == 'ALL') ) {
534 $my_cat_name = apply_filters('single_cat_title', get_the_category_by_ID($cat));
535 if ( !empty($my_cat_name) ) {
537 echo $prefix.strip_tags($my_cat_name);
539 return strip_tags($my_cat_name);
541 } else if ( is_tag() ) {
542 return single_tag_title($prefix, $display);
547 * Display or retrieve page title for tag post archive.
549 * Useful for tag template files for displaying the tag page title. It has less
550 * overhead than {@link wp_title()}, because of its limited implementation.
552 * It does not support placing the separator after the title, but by leaving the
553 * prefix parameter empty, you can set the title separator manually. The prefix
554 * does not automatically place a space between the prefix, so if there should
555 * be a space, the parameter value will need to have it at the end.
559 * @param string $prefix Optional. What to display before the title.
560 * @param bool $display Optional, default is true. Whether to display or retrieve title.
561 * @return string|null Title when retrieving, null when displaying or failure.
563 function single_tag_title($prefix = '', $display = true ) {
567 $tag_id = intval( get_query_var('tag_id') );
569 if ( !empty($tag_id) ) {
570 $my_tag = &get_term($tag_id, 'post_tag', OBJECT, 'display');
571 if ( is_wp_error( $my_tag ) )
573 $my_tag_name = apply_filters('single_tag_title', $my_tag->name);
574 if ( !empty($my_tag_name) ) {
576 echo $prefix . $my_tag_name;
584 * Display or retrieve page title for post archive based on date.
586 * Useful for when the template only needs to display the month and year, if
587 * either are available. Optimized for just this purpose, so if it is all that
588 * is needed, should be better than {@link wp_title()}.
590 * It does not support placing the separator after the title, but by leaving the
591 * prefix parameter empty, you can set the title separator manually. The prefix
592 * does not automatically place a space between the prefix, so if there should
593 * be a space, the parameter value will need to have it at the end.
597 * @param string $prefix Optional. What to display before the title.
598 * @param bool $display Optional, default is true. Whether to display or retrieve title.
599 * @return string|null Title when retrieving, null when displaying or failure.
601 function single_month_title($prefix = '', $display = true ) {
604 $m = get_query_var('m');
605 $year = get_query_var('year');
606 $monthnum = get_query_var('monthnum');
608 if ( !empty($monthnum) && !empty($year) ) {
610 $my_month = $wp_locale->get_month($monthnum);
611 } elseif ( !empty($m) ) {
612 $my_year = substr($m, 0, 4);
613 $my_month = $wp_locale->get_month(substr($m, 4, 2));
616 if ( empty($my_month) )
619 $result = $prefix . $my_month . $prefix . $my_year;
627 * Retrieve archive link content based on predefined or custom code.
629 * The format can be one of four styles. The 'link' for head element, 'option'
630 * for use in the select element, 'html' for use in list (either ol or ul HTML
631 * elements). Custom content is also supported using the before and after
634 * The 'link' format uses the link HTML element with the <em>archives</em>
635 * relationship. The before and after parameters are not used. The text
636 * parameter is used to describe the link.
638 * The 'option' format uses the option HTML element for use in select element.
639 * The value is the url parameter and the before and after parameters are used
640 * between the text description.
642 * The 'html' format, which is the default, uses the li HTML element for use in
643 * the list HTML elements. The before parameter is before the link and the after
644 * parameter is after the closing link.
646 * The custom format uses the before parameter before the link ('a' HTML
647 * element) and the after parameter after the closing link tag. If the above
648 * three values for the format are not used, then custom format is assumed.
652 * @link http://icecode.com/ link navigation hack by Orien
654 * @param string $url URL to archive.
655 * @param string $text Archive text description.
656 * @param string $format Optional, default is 'html'. Can be 'link', 'option', 'html', or custom.
657 * @param string $before Optional.
658 * @param string $after Optional.
659 * @return string HTML link content for archive.
661 function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') {
662 $text = wptexturize($text);
663 $title_text = attribute_escape($text);
664 $url = clean_url($url);
666 if ('link' == $format)
667 $link_html = "\t<link rel='archives' title='$title_text' href='$url' />\n";
668 elseif ('option' == $format)
669 $link_html = "\t<option value='$url'>$before $text $after</option>\n";
670 elseif ('html' == $format)
671 $link_html = "\t<li>$before<a href='$url' title='$title_text'>$text</a>$after</li>\n";
673 $link_html = "\t$before<a href='$url' title='$title_text'>$text</a>$after\n";
675 $link_html = apply_filters( "get_archives_link", $link_html );
681 * Display archive links based on type and format.
683 * The 'type' argument offers a few choices and by default will display monthly
684 * archive links. The other options for values are 'daily', 'weekly', 'monthly',
685 * 'yearly', 'postbypost' or 'alpha'. Both 'postbypost' and 'alpha' display the
686 * same archive link list, the difference between the two is that 'alpha'
687 * will order by post title and 'postbypost' will order by post date.
689 * The date archives will logically display dates with links to the archive post
690 * page. The 'postbypost' and 'alpha' values for 'type' argument will display
693 * The 'limit' argument will only display a limited amount of links, specified
694 * by the 'limit' integer value. By default, there is no limit. The
695 * 'show_post_count' argument will show how many posts are within the archive.
696 * By default, the 'show_post_count' argument is set to false.
698 * For the 'format', 'before', and 'after' arguments, see {@link
699 * get_archives_link()}. The values of these arguments have to do with that
704 * @param string|array $args Optional. Override defaults.
706 function wp_get_archives($args = '') {
707 global $wpdb, $wp_locale;
710 'type' => 'monthly', 'limit' => '',
711 'format' => 'html', 'before' => '',
712 'after' => '', 'show_post_count' => false,
716 $r = wp_parse_args( $args, $defaults );
717 extract( $r, EXTR_SKIP );
722 if ( '' != $limit ) {
723 $limit = absint($limit);
724 $limit = ' LIMIT '.$limit;
727 // this is what will separate dates on weekly archive links
728 $archive_week_separator = '–';
730 // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride
731 $archive_date_format_over_ride = 0;
733 // options for daily archive (only if you over-ride the general date format)
734 $archive_day_date_format = 'Y/m/d';
736 // options for weekly archive (only if you over-ride the general date format)
737 $archive_week_start_date_format = 'Y/m/d';
738 $archive_week_end_date_format = 'Y/m/d';
740 if ( !$archive_date_format_over_ride ) {
741 $archive_day_date_format = get_option('date_format');
742 $archive_week_start_date_format = get_option('date_format');
743 $archive_week_end_date_format = get_option('date_format');
747 $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r );
748 $join = apply_filters('getarchives_join', "", $r);
752 if ( 'monthly' == $type ) {
753 $query = "SELECT DISTINCT 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";
755 $cache = wp_cache_get( 'wp_get_archives' , 'general');
756 if ( !isset( $cache[ $key ] ) ) {
757 $arcresults = $wpdb->get_results($query);
758 $cache[ $key ] = $arcresults;
759 wp_cache_add( 'wp_get_archives', $cache, 'general' );
761 $arcresults = $cache[ $key ];
764 $afterafter = $after;
765 foreach ( (array) $arcresults as $arcresult ) {
766 $url = get_month_link( $arcresult->year, $arcresult->month );
767 $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year);
768 if ( $show_post_count )
769 $after = ' ('.$arcresult->posts.')' . $afterafter;
770 $output .= get_archives_link($url, $text, $format, $before, $after);
773 } elseif ('yearly' == $type) {
774 $query = "SELECT DISTINCT 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";
776 $cache = wp_cache_get( 'wp_get_archives' , 'general');
777 if ( !isset( $cache[ $key ] ) ) {
778 $arcresults = $wpdb->get_results($query);
779 $cache[ $key ] = $arcresults;
780 wp_cache_add( 'wp_get_archives', $cache, 'general' );
782 $arcresults = $cache[ $key ];
785 $afterafter = $after;
786 foreach ( (array) $arcresults as $arcresult) {
787 $url = get_year_link($arcresult->year);
788 $text = sprintf('%d', $arcresult->year);
789 if ($show_post_count)
790 $after = ' ('.$arcresult->posts.')' . $afterafter;
791 $output .= get_archives_link($url, $text, $format, $before, $after);
794 } elseif ( 'daily' == $type ) {
795 $query = "SELECT DISTINCT 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";
797 $cache = wp_cache_get( 'wp_get_archives' , 'general');
798 if ( !isset( $cache[ $key ] ) ) {
799 $arcresults = $wpdb->get_results($query);
800 $cache[ $key ] = $arcresults;
801 wp_cache_add( 'wp_get_archives', $cache, 'general' );
803 $arcresults = $cache[ $key ];
806 $afterafter = $after;
807 foreach ( (array) $arcresults as $arcresult ) {
808 $url = get_day_link($arcresult->year, $arcresult->month, $arcresult->dayofmonth);
809 $date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $arcresult->year, $arcresult->month, $arcresult->dayofmonth);
810 $text = mysql2date($archive_day_date_format, $date);
811 if ($show_post_count)
812 $after = ' ('.$arcresult->posts.')'.$afterafter;
813 $output .= get_archives_link($url, $text, $format, $before, $after);
816 } elseif ( 'weekly' == $type ) {
817 $start_of_week = get_option('start_of_week');
818 $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";
820 $cache = wp_cache_get( 'wp_get_archives' , 'general');
821 if ( !isset( $cache[ $key ] ) ) {
822 $arcresults = $wpdb->get_results($query);
823 $cache[ $key ] = $arcresults;
824 wp_cache_add( 'wp_get_archives', $cache, 'general' );
826 $arcresults = $cache[ $key ];
829 $afterafter = $after;
831 foreach ( (array) $arcresults as $arcresult ) {
832 if ( $arcresult->week != $arc_w_last ) {
833 $arc_year = $arcresult->yr;
834 $arc_w_last = $arcresult->week;
835 $arc_week = get_weekstartend($arcresult->yyyymmdd, get_option('start_of_week'));
836 $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']);
837 $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']);
838 $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);
839 $text = $arc_week_start . $archive_week_separator . $arc_week_end;
840 if ($show_post_count)
841 $after = ' ('.$arcresult->posts.')'.$afterafter;
842 $output .= get_archives_link($url, $text, $format, $before, $after);
846 } elseif ( ( 'postbypost' == $type ) || ('alpha' == $type) ) {
847 $orderby = ('alpha' == $type) ? "post_title ASC " : "post_date DESC ";
848 $query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $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 foreach ( (array) $arcresults as $arcresult ) {
860 if ( $arcresult->post_date != '0000-00-00 00:00:00' ) {
861 $url = get_permalink($arcresult);
862 $arc_title = $arcresult->post_title;
864 $text = strip_tags(apply_filters('the_title', $arc_title));
866 $text = $arcresult->ID;
867 $output .= get_archives_link($url, $text, $format, $before, $after);
879 * Get number of days since the start of the week.
882 * @usedby get_calendar()
884 * @param int $num Number of day.
885 * @return int Days since the start of the week.
887 function calendar_week_mod($num) {
889 return ($num - $base*floor($num/$base));
893 * Display calendar with days that have posts as links.
895 * The calendar is cached, which will be retrieved, if it exists. If there are
896 * no posts for the month, then it will not be displayed.
900 * @param bool $initial Optional, default is true. Use initial calendar names.
902 function get_calendar($initial = true) {
903 global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
905 $key = md5( $m . $monthnum . $year );
906 if ( $cache = wp_cache_get( 'get_calendar', 'calendar' ) ) {
907 if ( isset( $cache[ $key ] ) ) {
914 // Quick check. If we have no posts at all, abort!
916 $gotsome = $wpdb->get_var("SELECT ID from $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1");
921 if ( isset($_GET['w']) )
922 $w = ''.intval($_GET['w']);
924 // week_begins = 0 stands for Sunday
925 $week_begins = intval(get_option('start_of_week'));
927 // Let's figure out when we are
928 if ( !empty($monthnum) && !empty($year) ) {
929 $thismonth = ''.zeroise(intval($monthnum), 2);
930 $thisyear = ''.intval($year);
931 } elseif ( !empty($w) ) {
932 // We need to get the month from MySQL
933 $thisyear = ''.intval(substr($m, 0, 4));
934 $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's
935 $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('${thisyear}0101', INTERVAL $d DAY) ), '%m')");
936 } elseif ( !empty($m) ) {
937 $thisyear = ''.intval(substr($m, 0, 4));
938 if ( strlen($m) < 6 )
941 $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2);
943 $thisyear = gmdate('Y', current_time('timestamp'));
944 $thismonth = gmdate('m', current_time('timestamp'));
947 $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear);
949 // Get the next and previous month and year with at least one post
950 $previous = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
952 WHERE post_date < '$thisyear-$thismonth-01'
953 AND post_type = 'post' AND post_status = 'publish'
954 ORDER BY post_date DESC
956 $next = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
958 WHERE post_date > '$thisyear-$thismonth-01'
959 AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' )
960 AND post_type = 'post' AND post_status = 'publish'
961 ORDER BY post_date ASC
964 echo '<table id="wp-calendar" summary="' . __('Calendar') . '">
965 <caption>' . sprintf(_c('%1$s %2$s|Used as a calendar caption'), $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption>
971 for ( $wdcount=0; $wdcount<=6; $wdcount++ ) {
972 $myweek[] = $wp_locale->get_weekday(($wdcount+$week_begins)%7);
975 foreach ( $myweek as $wd ) {
976 $day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd);
977 echo "\n\t\t<th abbr=\"$wd\" scope=\"col\" title=\"$wd\">$day_name</th>";
988 echo "\n\t\t".'<td abbr="' . $wp_locale->get_month($previous->month) . '" colspan="3" id="prev"><a href="' .
989 get_month_link($previous->year, $previous->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($previous->month),
990 date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year))) . '">« ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
992 echo "\n\t\t".'<td colspan="3" id="prev" class="pad"> </td>';
995 echo "\n\t\t".'<td class="pad"> </td>';
998 echo "\n\t\t".'<td abbr="' . $wp_locale->get_month($next->month) . '" colspan="3" id="next"><a href="' .
999 get_month_link($next->year, $next->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($next->month),
1000 date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' »</a></td>';
1002 echo "\n\t\t".'<td colspan="3" id="next" class="pad"> </td>';
1012 // Get days with posts
1013 $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
1014 FROM $wpdb->posts WHERE MONTH(post_date) = '$thismonth'
1015 AND YEAR(post_date) = '$thisyear'
1016 AND post_type = 'post' AND post_status = 'publish'
1017 AND post_date < '" . current_time('mysql') . '\'', ARRAY_N);
1018 if ( $dayswithposts ) {
1019 foreach ( (array) $dayswithposts as $daywith ) {
1020 $daywithpost[] = $daywith[0];
1023 $daywithpost = array();
1026 if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'camino') !== false || strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'safari') !== false)
1027 $ak_title_separator = "\n";
1029 $ak_title_separator = ', ';
1031 $ak_titles_for_day = array();
1032 $ak_post_titles = $wpdb->get_results("SELECT post_title, DAYOFMONTH(post_date) as dom "
1033 ."FROM $wpdb->posts "
1034 ."WHERE YEAR(post_date) = '$thisyear' "
1035 ."AND MONTH(post_date) = '$thismonth' "
1036 ."AND post_date < '".current_time('mysql')."' "
1037 ."AND post_type = 'post' AND post_status = 'publish'"
1039 if ( $ak_post_titles ) {
1040 foreach ( (array) $ak_post_titles as $ak_post_title ) {
1042 $post_title = apply_filters( "the_title", $ak_post_title->post_title );
1043 $post_title = str_replace('"', '"', wptexturize( $post_title ));
1045 if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) )
1046 $ak_titles_for_day['day_'.$ak_post_title->dom] = '';
1047 if ( empty($ak_titles_for_day["$ak_post_title->dom"]) ) // first one
1048 $ak_titles_for_day["$ak_post_title->dom"] = $post_title;
1050 $ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . $post_title;
1055 // See how much we should pad in the beginning
1056 $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins);
1058 echo "\n\t\t".'<td colspan="'.$pad.'" class="pad"> </td>';
1060 $daysinmonth = intval(date('t', $unixmonth));
1061 for ( $day = 1; $day <= $daysinmonth; ++$day ) {
1062 if ( isset($newrow) && $newrow )
1063 echo "\n\t</tr>\n\t<tr>\n\t\t";
1066 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)) )
1067 echo '<td id="today">';
1071 if ( in_array($day, $daywithpost) ) // any posts today?
1072 echo '<a href="' . get_day_link($thisyear, $thismonth, $day) . "\" title=\"$ak_titles_for_day[$day]\">$day</a>";
1077 if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) )
1081 $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
1082 if ( $pad != 0 && $pad != 7 )
1083 echo "\n\t\t".'<td class="pad" colspan="'.$pad.'"> </td>';
1085 echo "\n\t</tr>\n\t</tbody>\n\t</table>";
1087 $output = ob_get_contents();
1090 $cache[ $key ] = $output;
1091 wp_cache_set( 'get_calendar', $cache, 'calendar' );
1095 * Purge the cached results of get_calendar.
1100 function delete_get_calendar_cache() {
1101 wp_cache_delete( 'get_calendar', 'calendar' );
1103 add_action( 'save_post', 'delete_get_calendar_cache' );
1104 add_action( 'delete_post', 'delete_get_calendar_cache' );
1105 add_action( 'update_option_start_of_week', 'delete_get_calendar_cache' );
1106 add_action( 'update_option_gmt_offset', 'delete_get_calendar_cache' );
1107 add_action( 'update_option_start_of_week', 'delete_get_calendar_cache' );
1110 * Display all of the allowed tags in HTML format with attributes.
1112 * This is useful for displaying in the comment area, which elements and
1113 * attributes are supported. As well as any plugins which want to display it.
1116 * @uses $allowedtags
1118 * @return string HTML allowed tags entity encoded.
1120 function allowed_tags() {
1121 global $allowedtags;
1123 foreach ( (array) $allowedtags as $tag => $attributes ) {
1124 $allowed .= '<'.$tag;
1125 if ( 0 < count($attributes) ) {
1126 foreach ( $attributes as $attribute => $limits ) {
1127 $allowed .= ' '.$attribute.'=""';
1132 return htmlentities($allowed);
1135 /***** Date/Time tags *****/
1138 * Outputs the date in iso8601 format for xml files.
1142 function the_date_xml() {
1144 echo mysql2date('Y-m-d', $post->post_date);
1148 * Display or Retrieve the date the post was written.
1150 * Will only output the date if the current post's date is different from the
1151 * previous one output.
1155 * @param string $d Optional. PHP date format defaults to the date_format option if not specified.
1156 * @param string $before Optional. Output before the date.
1157 * @param string $after Optional. Output after the date.
1158 * @param bool $echo Optional, default is display. Whether to echo the date or return it.
1159 * @return string|null Null if displaying, string if retrieving.
1161 function the_date($d='', $before='', $after='', $echo = true) {
1162 global $post, $day, $previousday;
1164 if ( $day != $previousday ) {
1165 $the_date .= $before;
1167 $the_date .= mysql2date(get_option('date_format'), $post->post_date);
1169 $the_date .= mysql2date($d, $post->post_date);
1170 $the_date .= $after;
1171 $previousday = $day;
1173 $the_date = apply_filters('the_date', $the_date, $d, $before, $after);
1181 * Display the date on which the post was last modified.
1185 * @param string $d Optional. PHP date format.
1188 function the_modified_date($d = '') {
1189 echo apply_filters('the_modified_date', get_the_modified_date($d), $d);
1193 * Retrieve the date on which the post was last modified.
1197 * @param string $d Optional. PHP date format. Defaults to the "date_format" option
1200 function get_the_modified_date($d = '') {
1202 $the_time = get_post_modified_time(get_option('date_format'));
1204 $the_time = get_post_modified_time($d);
1205 return apply_filters('get_the_modified_date', $the_time, $d);
1209 * Display the time at which the post was written.
1213 * @param string $d Either 'G', 'U', or php date format.
1215 function the_time( $d = '' ) {
1216 echo apply_filters('the_time', get_the_time( $d ), $d);
1220 * Retrieve the time at which the post was written.
1224 * @param string $d Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
1225 * @param int|object $post Optional post ID or object. Default is global $post object.
1228 function get_the_time( $d = '', $post = null ) {
1229 $post = get_post($post);
1232 $the_time = get_post_time(get_option('time_format'), false, $post);
1234 $the_time = get_post_time($d, false, $post);
1235 return apply_filters('get_the_time', $the_time, $d, $post);
1239 * Retrieve the time at which the post was written.
1243 * @param string $d Either 'G', 'U', or php date format.
1244 * @param bool $gmt Whether of not to return the gmt time.
1245 * @param int|object $post Optional post ID or object. Default is global $post object.
1248 function get_post_time( $d = 'U', $gmt = false, $post = null ) { // returns timestamp
1249 $post = get_post($post);
1252 $time = $post->post_date_gmt;
1254 $time = $post->post_date;
1256 $time = mysql2date($d, $time);
1257 return apply_filters('get_post_time', $time, $d, $gmt);
1261 * Display the time at which the post was last modified.
1265 * @param string $d Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
1267 function the_modified_time($d = '') {
1268 echo apply_filters('the_modified_time', get_the_modified_time($d), $d);
1272 * Retrieve the time at which the post was last modified.
1276 * @param string $d Either 'G', 'U', or php date format defaults to the value specified in the time_format option.
1279 function get_the_modified_time($d = '') {
1281 $the_time = get_post_modified_time(get_option('time_format'));
1283 $the_time = get_post_modified_time($d);
1284 return apply_filters('get_the_modified_time', $the_time, $d);
1288 * Retrieve the time at which the post was last modified.
1292 * @param string $d Either 'G', 'U', or php date format.
1293 * @param bool $gmt Whether of not to return the gmt time.
1294 * @return string Returns timestamp
1296 function get_post_modified_time( $d = 'U', $gmt = false ) {
1300 $time = $post->post_modified_gmt;
1302 $time = $post->post_modified;
1303 $time = mysql2date($d, $time);
1305 return apply_filters('get_the_modified_time', $time, $d, $gmt);
1309 * Display the weekday on which the post was written.
1315 function the_weekday() {
1316 global $wp_locale, $post;
1317 $the_weekday = $wp_locale->get_weekday(mysql2date('w', $post->post_date));
1318 $the_weekday = apply_filters('the_weekday', $the_weekday);
1323 * Display the weekday on which the post was written.
1325 * Will only output the weekday if the current post's weekday is different from
1326 * the previous one output.
1330 * @param string $before output before the date.
1331 * @param string $after output after the date.
1333 function the_weekday_date($before='',$after='') {
1334 global $wp_locale, $post, $day, $previousweekday;
1335 $the_weekday_date = '';
1336 if ( $day != $previousweekday ) {
1337 $the_weekday_date .= $before;
1338 $the_weekday_date .= $wp_locale->get_weekday(mysql2date('w', $post->post_date));
1339 $the_weekday_date .= $after;
1340 $previousweekday = $day;
1342 $the_weekday_date = apply_filters('the_weekday_date', $the_weekday_date, $before, $after);
1343 echo $the_weekday_date;
1347 * Fire the wp_head action
1350 * @uses do_action() Calls 'wp_head' hook.
1352 function wp_head() {
1353 do_action('wp_head');
1357 * Fire the wp_footer action
1360 * @uses do_action() Calls 'wp_footer' hook.
1362 function wp_footer() {
1363 do_action('wp_footer');
1367 * Display the link to the Really Simple Discovery service endpoint.
1369 * @link http://archipelago.phrasewise.com/rsd
1372 function rsd_link() {
1373 echo '<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . get_bloginfo('wpurl') . "/xmlrpc.php?rsd\" />\n";
1377 * Display the link to the Windows Live Writer manifest file.
1379 * @link http://msdn.microsoft.com/en-us/library/bb463265.aspx
1382 function wlwmanifest_link() {
1383 echo '<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="'
1384 . get_bloginfo('wpurl') . '/wp-includes/wlwmanifest.xml" /> ' . "\n";
1388 * Display a noindex meta tag if required by the blog configuration.
1390 * If a blog is marked as not being public then the noindex meta tag will be
1391 * output to tell web robots not to index the page content.
1395 function noindex() {
1396 // If the blog is not public, tell robots to go away.
1397 if ( '0' == get_option('blog_public') )
1398 echo "<meta name='robots' content='noindex,nofollow' />\n";
1402 * Determine if TinyMCE is available.
1404 * Checks to see if the user has deleted the tinymce files to slim down there WordPress install.
1408 * @return bool Whether of not TinyMCE exists.
1410 function rich_edit_exists() {
1411 global $wp_rich_edit_exists;
1412 if ( !isset($wp_rich_edit_exists) )
1413 $wp_rich_edit_exists = file_exists(ABSPATH . WPINC . '/js/tinymce/tiny_mce.js');
1414 return $wp_rich_edit_exists;
1418 * Whether or not the user should have a WYSIWIG editor.
1420 * Checks that the user requires a WYSIWIG editor and that the editor is
1421 * supported in the users browser.
1427 function user_can_richedit() {
1428 global $wp_rich_edit, $pagenow;
1430 if ( !isset( $wp_rich_edit) ) {
1431 if ( get_user_option( 'rich_editing' ) == 'true' &&
1432 ( ( preg_match( '!AppleWebKit/(\d+)!', $_SERVER['HTTP_USER_AGENT'], $match ) && intval($match[1]) >= 420 ) ||
1433 !preg_match( '!opera[ /][2-8]|konqueror|safari!i', $_SERVER['HTTP_USER_AGENT'] ) )
1434 && 'comment.php' != $pagenow ) {
1435 $wp_rich_edit = true;
1437 $wp_rich_edit = false;
1441 return apply_filters('user_can_richedit', $wp_rich_edit);
1445 * Find out which editor should be displayed by default.
1447 * Works out which of the two editors to display as the current editor for a
1452 * @return string Either 'tinymce', or 'html', or 'test'
1454 function wp_default_editor() {
1455 $r = user_can_richedit() ? 'tinymce' : 'html'; // defaults
1456 if ( $user = wp_get_current_user() ) { // look for cookie
1457 $ed = get_user_setting('editor', 'tinymce');
1458 $r = ( in_array($ed, array('tinymce', 'html', 'test') ) ) ? $ed : $r;
1460 return apply_filters( 'wp_default_editor', $r ); // filter
1464 * Display visual editor forms: TinyMCE, or HTML, or both.
1466 * The amount of rows the text area will have for the content has to be between
1467 * 3 and 100 or will default at 12. There is only one option used for all users,
1468 * named 'default_post_edit_rows'.
1470 * If the user can not use the rich editor (TinyMCE), then the switch button
1471 * will not be displayed.
1475 * @param string $content Textarea content.
1476 * @param string $id HTML ID attribute value.
1477 * @param string $prev_id HTML ID name for switching back and forth between visual editors.
1478 * @param bool $media_buttons Optional, default is true. Whether to display media buttons.
1479 * @param int $tab_index Optional, default is 2. Tabindex for textarea element.
1481 function the_editor($content, $id = 'content', $prev_id = 'title', $media_buttons = true, $tab_index = 2) {
1482 $rows = get_option('default_post_edit_rows');
1483 if (($rows < 3) || ($rows > 100))
1486 if ( !current_user_can( 'upload_files' ) )
1487 $media_buttons = false;
1489 $richedit = user_can_richedit();
1490 $rows = "rows='$rows'";
1492 if ( $richedit || $media_buttons ) { ?>
1493 <div id="editor-toolbar">
1494 <?php if ( $richedit ) {
1495 $wp_default_editor = wp_default_editor(); ?>
1496 <div class="zerosize"><input accesskey="e" type="button" onclick="switchEditors.go('<?php echo $id; ?>')" /></div>
1497 <?php if ( 'html' == $wp_default_editor ) {
1498 add_filter('the_editor_content', 'wp_htmledit_pre'); ?>
1499 <a id="edButtonHTML" class="active" onclick="switchEditors.go('<?php echo $id; ?>', 'html');"><?php _e('HTML'); ?></a>
1500 <a id="edButtonPreview" onclick="switchEditors.go('<?php echo $id; ?>', 'tinymce');"><?php _e('Visual'); ?></a>
1502 add_filter('the_editor_content', 'wp_richedit_pre'); ?>
1503 <a id="edButtonHTML" onclick="switchEditors.go('<?php echo $id; ?>', 'html');"><?php _e('HTML'); ?></a>
1504 <a id="edButtonPreview" class="active" onclick="switchEditors.go('<?php echo $id; ?>', 'tinymce');"><?php _e('Visual'); ?></a>
1508 if ( $media_buttons ) { ?>
1509 <div id="media-buttons" class="hide-if-no-js">
1510 <?php do_action( 'media_buttons' ); ?>
1516 <div id="quicktags">
1517 <?php wp_print_scripts( 'quicktags' ); ?>
1518 <script type="text/javascript">edToolbar()</script>
1521 <?php $the_editor = apply_filters('the_editor', "<div id='editorcontainer'><textarea $rows cols='40' name='$id' tabindex='$tab_index' id='$id'>%s</textarea></div>\n");
1522 $the_editor_content = apply_filters('the_editor_content', $content);
1524 printf($the_editor, $the_editor_content);
1527 <script type="text/javascript">
1529 edCanvas = document.getElementById('<?php echo $id; ?>');
1530 <?php if ( user_can_richedit() && $prev_id ) { ?>
1531 var dotabkey = true;
1532 // If tinyMCE is defined.
1533 if ( typeof tinyMCE != 'undefined' ) {
1534 // This code is meant to allow tabbing from Title to Post (TinyMCE).
1535 jQuery('#<?php echo $prev_id; ?>')[jQuery.browser.opera ? 'keypress' : 'keydown'](function (e) {
1536 if (e.which == 9 && !e.shiftKey && !e.controlKey && !e.altKey) {
1537 if ( (jQuery("#post_ID").val() < 1) && (jQuery("#title").val().length > 0) ) { autosave(); }
1538 if ( tinyMCE.activeEditor && ! tinyMCE.activeEditor.isHidden() && dotabkey ) {
1541 tinyMCE.activeEditor.focus();
1554 * Retrieve the contents of the search WordPress query variable.
1560 function get_search_query() {
1561 return apply_filters( 'get_search_query', stripslashes( get_query_var( 's' ) ) );
1565 * Display the contents of the search query variable.
1567 * The search query string is passed through {@link attribute_escape()}
1568 * to ensure that it is safe for placing in an html attribute.
1570 * @uses attribute_escape
1573 function the_search_query() {
1574 echo attribute_escape( apply_filters( 'the_search_query', get_search_query() ) );
1578 * Display the language attributes for the html tag.
1580 * Builds up a set of html attributes containing the text direction and language
1581 * information for the page.
1585 * @param string $doctype The type of html document (xhtml|html).
1587 function language_attributes($doctype = 'html') {
1588 $attributes = array();
1591 if ( $dir = get_bloginfo('text_direction') )
1592 $attributes[] = "dir=\"$dir\"";
1594 if ( $lang = get_bloginfo('language') ) {
1595 if ( get_option('html_type') == 'text/html' || $doctype == 'html' )
1596 $attributes[] = "lang=\"$lang\"";
1598 if ( get_option('html_type') != 'text/html' || $doctype == 'xhtml' )
1599 $attributes[] = "xml:lang=\"$lang\"";
1602 $output = implode(' ', $attributes);
1603 $output = apply_filters('language_attributes', $output);
1608 * Retrieve paginated link for archive post pages.
1610 * Technically, the function can be used to create paginated link list for any
1611 * area. The 'base' argument is used to reference the url, which will be used to
1612 * create the paginated links. The 'format' argument is then used for replacing
1613 * the page number. It is however, most likely and by default, to be used on the
1614 * archive post pages.
1616 * The 'type' argument controls format of the returned value. The default is
1617 * 'plain', which is just a string with the links separated by a newline
1618 * character. The other possible values are either 'array' or 'list'. The
1619 * 'array' value will return an array of the paginated link list to offer full
1620 * control of display. The 'list' value will place all of the paginated links in
1621 * an unordered HTML list.
1623 * The 'total' argument is the total amount of pages and is an integer. The
1624 * 'current' argument is the current page number and is also an integer.
1626 * An example of the 'base' argument is "http://example.com/all_posts.php%_%"
1627 * and the '%_%' is required. The '%_%' will be replaced by the contents of in
1628 * the 'format' argument. An example for the 'format' argument is "?page=%#%"
1629 * and the '%#%' is also required. The '%#%' will be replaced with the page
1632 * You can include the previous and next links in the list by setting the
1633 * 'prev_next' argument to true, which it is by default. You can set the
1634 * previous text, by using the 'prev_text' argument. You can set the next text
1635 * by setting the 'next_text' argument.
1637 * If the 'show_all' argument is set to true, then it will show all of the pages
1638 * instead of a short list of the pages near the current page. By default, the
1639 * 'show_all' is set to false and controlled by the 'end_size' and 'mid_size'
1640 * arguments. The 'end_size' argument is how many numbers on either the start
1641 * and the end list edges, by default is 1. The 'mid_size' argument is how many
1642 * numbers to either side of current page, but not including current page.
1644 * It is possible to add query vars to the link by using the 'add_args' argument
1645 * and see {@link add_query_arg()} for more information.
1649 * @param string|array $args Optional. Override defaults.
1650 * @return array|string String of page links or array of page links.
1652 function paginate_links( $args = '' ) {
1654 'base' => '%_%', // http://example.com/all_posts.php%_% : %_% is replaced by format (below)
1655 'format' => '?page=%#%', // ?page=%#% : %#% is replaced by the page number
1658 'show_all' => false,
1659 'prev_next' => true,
1660 'prev_text' => __('« Previous'),
1661 'next_text' => __('Next »'),
1665 'add_args' => false, // array of query args to add
1666 'add_fragment' => ''
1669 $args = wp_parse_args( $args, $defaults );
1670 extract($args, EXTR_SKIP);
1672 // Who knows what else people pass in $args
1673 $total = (int) $total;
1676 $current = (int) $current;
1677 $end_size = 0 < (int) $end_size ? (int) $end_size : 1; // Out of bounds? Make it the default.
1678 $mid_size = 0 <= (int) $mid_size ? (int) $mid_size : 2;
1679 $add_args = is_array($add_args) ? $add_args : false;
1681 $page_links = array();
1685 if ( $prev_next && $current && 1 < $current ) :
1686 $link = str_replace('%_%', 2 == $current ? '' : $format, $base);
1687 $link = str_replace('%#%', $current - 1, $link);
1689 $link = add_query_arg( $add_args, $link );
1690 $link .= $add_fragment;
1691 $page_links[] = "<a class='prev page-numbers' href='" . clean_url($link) . "'>$prev_text</a>";
1693 for ( $n = 1; $n <= $total; $n++ ) :
1694 $n_display = number_format_i18n($n);
1695 if ( $n == $current ) :
1696 $page_links[] = "<span class='page-numbers current'>$n_display</span>";
1699 if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) :
1700 $link = str_replace('%_%', 1 == $n ? '' : $format, $base);
1701 $link = str_replace('%#%', $n, $link);
1703 $link = add_query_arg( $add_args, $link );
1704 $link .= $add_fragment;
1705 $page_links[] = "<a class='page-numbers' href='" . clean_url($link) . "'>$n_display</a>";
1707 elseif ( $dots && !$show_all ) :
1708 $page_links[] = "<span class='page-numbers dots'>...</span>";
1713 if ( $prev_next && $current && ( $current < $total || -1 == $total ) ) :
1714 $link = str_replace('%_%', $format, $base);
1715 $link = str_replace('%#%', $current + 1, $link);
1717 $link = add_query_arg( $add_args, $link );
1718 $link .= $add_fragment;
1719 $page_links[] = "<a class='next page-numbers' href='" . clean_url($link) . "'>$next_text</a>";
1726 $r .= "<ul class='page-numbers'>\n\t<li>";
1727 $r .= join("</li>\n\t<li>", $page_links);
1728 $r .= "</li>\n</ul>\n";
1731 $r = join("\n", $page_links);
1738 * Registers an admin colour scheme css file.
1740 * Allows a plugin to register a new admin colour scheme. For example:
1742 * wp_admin_css_color('classic', __('Classic'), admin_url("css/colors-classic.css"),
1743 * array('#07273E', '#14568A', '#D54E21', '#2683AE'));
1748 * @param string $key The unique key for this theme.
1749 * @param string $name The name of the theme.
1750 * @param string $url The url of the css file containing the colour scheme.
1751 * @param array @colors An array of CSS color definitions which are used to give the user a feel for the theme.
1753 function wp_admin_css_color($key, $name, $url, $colors = array()) {
1754 global $_wp_admin_css_colors;
1756 if ( !isset($_wp_admin_css_colors) )
1757 $_wp_admin_css_colors = array();
1759 $_wp_admin_css_colors[$key] = (object) array('name' => $name, 'url' => $url, 'colors' => $colors);
1763 * Display the URL of a WordPress admin CSS file.
1765 * @see WP_Styles::_css_href and its style_loader_src filter.
1769 * @param string $file file relative to wp-admin/ without its ".css" extension.
1771 function wp_admin_css_uri( $file = 'wp-admin' ) {
1772 if ( defined('WP_INSTALLING') ) {
1773 $_file = "./$file.css";
1775 $_file = admin_url("$file.css");
1777 $_file = add_query_arg( 'version', get_bloginfo( 'version' ), $_file );
1779 return apply_filters( 'wp_admin_css_uri', $_file, $file );
1783 * Enqueues or directly prints a stylesheet link to the specified CSS file.
1785 * "Intelligently" decides to enqueue or to print the CSS file. If the
1786 * 'wp_print_styles' action has *not* yet been called, the CSS file will be
1787 * enqueued. If the wp_print_styles action *has* been called, the CSS link will
1788 * be printed. Printing may be forced by passing TRUE as the $force_echo
1789 * (second) parameter.
1791 * For backward compatibility with WordPress 2.3 calling method: If the $file
1792 * (first) parameter does not correspond to a registered CSS file, we assume
1793 * $file is a file relative to wp-admin/ without its ".css" extension. A
1794 * stylesheet link to that generated URL is printed.
1796 * @package WordPress
1798 * @uses $wp_styles WordPress Styles Object
1800 * @param string $file Style handle name or file name (without ".css" extension) relative to wp-admin/
1801 * @param bool $force_echo Optional. Force the stylesheet link to be printed rather than enqueued.
1803 function wp_admin_css( $file = 'wp-admin', $force_echo = false ) {
1805 if ( !is_a($wp_styles, 'WP_Styles') )
1806 $wp_styles = new WP_Styles();
1808 // For backward compatibility
1809 $handle = 0 === strpos( $file, 'css/' ) ? substr( $file, 4 ) : $file;
1811 if ( $wp_styles->query( $handle ) ) {
1812 if ( $force_echo || did_action( 'wp_print_styles' ) ) // we already printed the style queue. Print this one immediately
1813 wp_print_styles( $handle );
1814 else // Add to style queue
1815 wp_enqueue_style( $handle );
1819 echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . clean_url( wp_admin_css_uri( $file ) ) . "' type='text/css' />\n", $file );
1820 if ( 'rtl' == get_bloginfo( 'text_direction' ) )
1821 echo apply_filters( 'wp_admin_css', "<link rel='stylesheet' href='" . clean_url( wp_admin_css_uri( "$file-rtl" ) ) . "' type='text/css' />\n", "$file-rtl" );
1825 * Enqueues the default ThickBox js and css.
1827 * If any of the settings need to be changed, this can be done with another js
1828 * file similar to media-upload.js and theme-preview.js. That file should
1829 * require array('thickbox') to ensure it is loaded after.
1833 function add_thickbox() {
1834 wp_enqueue_script( 'thickbox' );
1835 wp_enqueue_style( 'thickbox' );
1839 * Display the XHTML generator that is generated on the wp_head hook.
1843 function wp_generator() {
1844 the_generator( apply_filters( 'wp_generator_type', 'xhtml' ) );
1848 * Display the generator XML or Comment for RSS, ATOM, etc.
1850 * Returns the correct generator type for the requested output format. Allows
1851 * for a plugin to filter generators overall the the_generator filter.
1854 * @uses apply_filters() Calls 'the_generator' hook.
1856 * @param string $type The type of generator to output - (html|xhtml|atom|rss2|rdf|comment|export).
1858 function the_generator( $type ) {
1859 echo apply_filters('the_generator', get_the_generator($type), $type) . "\n";
1863 * Creates the generator XML or Comment for RSS, ATOM, etc.
1865 * Returns the correct generator type for the requested output format. Allows
1866 * for a plugin to filter generators on an individual basis using the
1867 * 'get_the_generator_{$type}' filter.
1870 * @uses apply_filters() Calls 'get_the_generator_$type' hook.
1872 * @param string $type The type of generator to return - (html|xhtml|atom|rss2|rdf|comment|export).
1873 * @return string The HTML content for the generator.
1875 function get_the_generator( $type ) {
1878 $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '">' . "\n";
1881 $gen = '<meta name="generator" content="WordPress ' . get_bloginfo( 'version' ) . '" />' . "\n";
1884 $gen = '<generator uri="http://wordpress.org/" version="' . get_bloginfo_rss( 'version' ) . '">WordPress</generator>';
1887 $gen = '<generator>http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '</generator>';
1890 $gen = '<admin:generatorAgent rdf:resource="http://wordpress.org/?v=' . get_bloginfo_rss( 'version' ) . '" />';
1893 $gen = '<!-- generator="WordPress/' . get_bloginfo( 'version' ) . '" -->';
1896 $gen = '<!-- generator="WordPress/' . get_bloginfo_rss('version') . '" created="'. date('Y-m-d H:i') . '"-->';
1899 return apply_filters( "get_the_generator_{$type}", $gen, $type );