PHP Cross Reference of WordPress Subversion HEAD |
| [ Index ] [ Classes ] [ Functions ] [ Variables ] [ Constants ] |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* Note: these tags go anywhere in the template */ 4 5 function get_header() { 6 do_action( 'get_header' ); 7 if ( file_exists( TEMPLATEPATH . '/header.php') ) 8 load_template( TEMPLATEPATH . '/header.php'); 9 else 10 load_template( ABSPATH . 'wp-content/themes/default/header.php'); 11 } 12 13 14 function get_footer() { 15 do_action( 'get_footer' ); 16 if ( file_exists( TEMPLATEPATH . '/footer.php') ) 17 load_template( TEMPLATEPATH . '/footer.php'); 18 else 19 load_template( ABSPATH . 'wp-content/themes/default/footer.php'); 20 } 21 22 23 function get_sidebar() { 24 do_action( 'get_sidebar' ); 25 if ( file_exists( TEMPLATEPATH . '/sidebar.php') ) 26 load_template( TEMPLATEPATH . '/sidebar.php'); 27 else 28 load_template( ABSPATH . 'wp-content/themes/default/sidebar.php'); 29 } 30 31 32 function wp_loginout() { 33 if ( ! is_user_logged_in() ) 34 $link = '<a href="' . get_option('siteurl') . '/wp-login.php">' . __('Log in') . '</a>'; 35 else 36 $link = '<a href="' . get_option('siteurl') . '/wp-login.php?action=logout">' . __('Log out') . '</a>'; 37 38 echo apply_filters('loginout', $link); 39 } 40 41 42 function wp_register( $before = '<li>', $after = '</li>' ) { 43 44 if ( ! is_user_logged_in() ) { 45 if ( get_option('users_can_register') ) 46 $link = $before . '<a href="' . get_option('siteurl') . '/wp-login.php?action=register">' . __('Register') . '</a>' . $after; 47 else 48 $link = ''; 49 } else { 50 $link = $before . '<a href="' . get_option('siteurl') . '/wp-admin/">' . __('Site Admin') . '</a>' . $after; 51 } 52 53 echo apply_filters('register', $link); 54 } 55 56 57 function wp_meta() { 58 do_action('wp_meta'); 59 } 60 61 62 function bloginfo($show='') { 63 echo get_bloginfo($show, 'display'); 64 } 65 66 /** 67 * Note: some of these values are DEPRECATED. Meaning they could be 68 * taken out at any time and shouldn't be relied upon. Options 69 * without "// DEPRECATED" are the preferred and recommended ways 70 * to get the information. 71 */ 72 function get_bloginfo($show = '', $filter = 'raw') { 73 74 switch($show) { 75 case 'url' : 76 case 'home' : // DEPRECATED 77 case 'siteurl' : // DEPRECATED 78 $output = get_option('home'); 79 break; 80 case 'wpurl' : 81 $output = get_option('siteurl'); 82 break; 83 case 'description': 84 $output = get_option('blogdescription'); 85 break; 86 case 'rdf_url': 87 $output = get_feed_link('rdf'); 88 break; 89 case 'rss_url': 90 $output = get_feed_link('rss'); 91 break; 92 case 'rss2_url': 93 $output = get_feed_link('rss2'); 94 break; 95 case 'atom_url': 96 $output = get_feed_link('atom'); 97 break; 98 case 'comments_atom_url': 99 $output = get_feed_link('comments_atom'); 100 break; 101 case 'comments_rss2_url': 102 $output = get_feed_link('comments_rss2'); 103 break; 104 case 'pingback_url': 105 $output = get_option('siteurl') .'/xmlrpc.php'; 106 break; 107 case 'stylesheet_url': 108 $output = get_stylesheet_uri(); 109 break; 110 case 'stylesheet_directory': 111 $output = get_stylesheet_directory_uri(); 112 break; 113 case 'template_directory': 114 case 'template_url': 115 $output = get_template_directory_uri(); 116 break; 117 case 'admin_email': 118 $output = get_option('admin_email'); 119 break; 120 case 'charset': 121 $output = get_option('blog_charset'); 122 if ('' == $output) $output = 'UTF-8'; 123 break; 124 case 'html_type' : 125 $output = get_option('html_type'); 126 break; 127 case 'version': 128 global $wp_version; 129 $output = $wp_version; 130 break; 131 case 'language': 132 $output = get_locale(); 133 $output = str_replace('_', '-', $output); 134 break; 135 case 'text_direction': 136 global $wp_locale; 137 $output = $wp_locale->text_direction; 138 break; 139 case 'name': 140 default: 141 $output = get_option('blogname'); 142 break; 143 } 144 145 $url = true; 146 if (strpos($show, 'url') === false && 147 strpos($show, 'directory') === false && 148 strpos($show, 'home') === false) 149 $url = false; 150 151 if ( 'display' == $filter ) { 152 if ( $url ) 153 $output = apply_filters('bloginfo_url', $output, $show); 154 else 155 $output = apply_filters('bloginfo', $output, $show); 156 } 157 158 return $output; 159 } 160 161 162 function wp_title($sep = '»', $display = true) { 163 global $wpdb, $wp_locale, $wp_query; 164 165 $cat = get_query_var('cat'); 166 $tag = get_query_var('tag_id'); 167 $p = get_query_var('p'); 168 $name = get_query_var('name'); 169 $category_name = get_query_var('category_name'); 170 $author = get_query_var('author'); 171 $author_name = get_query_var('author_name'); 172 $m = get_query_var('m'); 173 $year = get_query_var('year'); 174 $monthnum = get_query_var('monthnum'); 175 $day = get_query_var('day'); 176 $title = ''; 177 178 // If there's a category 179 if ( !empty($cat) ) { 180 // category exclusion 181 if ( !stristr($cat,'-') ) 182 $title = apply_filters('single_cat_title', get_the_category_by_ID($cat)); 183 } elseif ( !empty($category_name) ) { 184 if ( stristr($category_name,'/') ) { 185 $category_name = explode('/',$category_name); 186 if ( $category_name[count($category_name)-1] ) 187 $category_name = $category_name[count($category_name)-1]; // no trailing slash 188 else 189 $category_name = $category_name[count($category_name)-2]; // there was a trailling slash 190 } 191 $cat = get_term_by('slug', $category_name, 'category', OBJECT, 'display'); 192 if ( $cat ) 193 $title = apply_filters('single_cat_title', $cat->name); 194 } 195 196 if ( !empty($tag) ) { 197 $tag = get_term($tag, 'post_tag', OBJECT, 'display'); 198 if ( is_wp_error( $tag ) ) 199 return $tag; 200 if ( ! empty($tag->name) ) 201 $title = apply_filters('single_tag_title', $tag->name); 202 } 203 204 // If there's an author 205 if ( !empty($author) ) { 206 $title = get_userdata($author); 207 $title = $title->display_name; 208 } 209 if ( !empty($author_name) ) { 210 // We do a direct query here because we don't cache by nicename. 211 $title = $wpdb->get_var($wpdb->prepare("SELECT display_name FROM $wpdb->users WHERE user_nicename = %s", $author_name)); 212 } 213 214 // If there's a month 215 if ( !empty($m) ) { 216 $my_year = substr($m, 0, 4); 217 $my_month = $wp_locale->get_month(substr($m, 4, 2)); 218 $my_day = intval(substr($m, 6, 2)); 219 $title = "$my_year" . ($my_month ? "$sep $my_month" : "") . ($my_day ? "$sep $my_day" : ""); 220 } 221 222 if ( !empty($year) ) { 223 $title = $year; 224 if ( !empty($monthnum) ) 225 $title .= " $sep " . $wp_locale->get_month($monthnum); 226 if ( !empty($day) ) 227 $title .= " $sep " . zeroise($day, 2); 228 } 229 230 // If there is a post 231 if ( is_single() || is_page() ) { 232 $post = $wp_query->get_queried_object(); 233 $title = strip_tags( apply_filters( 'single_post_title', $post->post_title ) ); 234 } 235 236 $prefix = ''; 237 if ( !empty($title) ) 238 $prefix = " $sep "; 239 240 $title = $prefix . $title; 241 $title = apply_filters('wp_title', $title, $sep); 242 243 // Send it out 244 if ( $display ) 245 echo $title; 246 else 247 return $title; 248 } 249 250 251 function single_post_title($prefix = '', $display = true) { 252 global $wpdb; 253 $p = get_query_var('p'); 254 $name = get_query_var('name'); 255 256 if ( intval($p) || '' != $name ) { 257 if ( !$p ) 258 $p = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_name = %s", $name)); 259 $post = & get_post($p); 260 $title = $post->post_title; 261 $title = apply_filters('single_post_title', $title); 262 if ( $display ) 263 echo $prefix.strip_tags($title); 264 else 265 return strip_tags($title); 266 } 267 } 268 269 270 function single_cat_title($prefix = '', $display = true ) { 271 $cat = intval( get_query_var('cat') ); 272 if ( !empty($cat) && !(strtoupper($cat) == 'ALL') ) { 273 $my_cat_name = apply_filters('single_cat_title', get_the_category_by_ID($cat)); 274 if ( !empty($my_cat_name) ) { 275 if ( $display ) 276 echo $prefix.strip_tags($my_cat_name); 277 else 278 return strip_tags($my_cat_name); 279 } 280 } else if ( is_tag() ) { 281 return single_tag_title($prefix, $display); 282 } 283 } 284 285 286 function single_tag_title($prefix = '', $display = true ) { 287 if ( !is_tag() ) 288 return; 289 290 $tag_id = intval( get_query_var('tag_id') ); 291 292 if ( !empty($tag_id) ) { 293 $my_tag = &get_term($tag_id, 'post_tag', OBJECT, 'display'); 294 if ( is_wp_error( $my_tag ) ) 295 return false; 296 $my_tag_name = apply_filters('single_tag_title', $my_tag->name); 297 if ( !empty($my_tag_name) ) { 298 if ( $display ) 299 echo $prefix . $my_tag_name; 300 else 301 return $my_tag_name; 302 } 303 } 304 } 305 306 307 function single_month_title($prefix = '', $display = true ) { 308 global $wp_locale; 309 310 $m = get_query_var('m'); 311 $year = get_query_var('year'); 312 $monthnum = get_query_var('monthnum'); 313 314 if ( !empty($monthnum) && !empty($year) ) { 315 $my_year = $year; 316 $my_month = $wp_locale->get_month($monthnum); 317 } elseif ( !empty($m) ) { 318 $my_year = substr($m, 0, 4); 319 $my_month = $wp_locale->get_month(substr($m, 4, 2)); 320 } 321 322 if ( empty($my_month) ) 323 return false; 324 325 $result = $prefix . $my_month . $prefix . $my_year; 326 327 if ( !$display ) 328 return $result; 329 echo $result; 330 } 331 332 333 /* link navigation hack by Orien http://icecode.com/ */ 334 function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') { 335 $text = wptexturize($text); 336 $title_text = attribute_escape($text); 337 $url = clean_url($url); 338 339 if ('link' == $format) 340 return "\t<link rel='archives' title='$title_text' href='$url' />\n"; 341 elseif ('option' == $format) 342 return "\t<option value='$url'>$before $text $after</option>\n"; 343 elseif ('html' == $format) 344 return "\t<li>$before<a href='$url' title='$title_text'>$text</a>$after</li>\n"; 345 else // custom 346 return "\t$before<a href='$url' title='$title_text'>$text</a>$after\n"; 347 } 348 349 350 function wp_get_archives($args = '') { 351 global $wpdb, $wp_locale; 352 353 $defaults = array( 354 'type' => 'monthly', 'limit' => '', 355 'format' => 'html', 'before' => '', 356 'after' => '', 'show_post_count' => false 357 ); 358 359 $r = wp_parse_args( $args, $defaults ); 360 extract( $r, EXTR_SKIP ); 361 362 if ( '' == $type ) 363 $type = 'monthly'; 364 365 if ( '' != $limit ) { 366 $limit = abs(intval($limit)); 367 $limit = ' LIMIT '.$limit; 368 } 369 370 // this is what will separate dates on weekly archive links 371 $archive_week_separator = '–'; 372 373 // over-ride general date format ? 0 = no: use the date format set in Options, 1 = yes: over-ride 374 $archive_date_format_over_ride = 0; 375 376 // options for daily archive (only if you over-ride the general date format) 377 $archive_day_date_format = 'Y/m/d'; 378 379 // options for weekly archive (only if you over-ride the general date format) 380 $archive_week_start_date_format = 'Y/m/d'; 381 $archive_week_end_date_format = 'Y/m/d'; 382 383 if ( !$archive_date_format_over_ride ) { 384 $archive_day_date_format = get_option('date_format'); 385 $archive_week_start_date_format = get_option('date_format'); 386 $archive_week_end_date_format = get_option('date_format'); 387 } 388 389 $add_hours = intval(get_option('gmt_offset')); 390 $add_minutes = intval(60 * (get_option('gmt_offset') - $add_hours)); 391 392 //filters 393 $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r ); 394 $join = apply_filters('getarchives_join', "", $r); 395 396 if ( 'monthly' == $type ) { 397 $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"; 398 $key = md5($query); 399 $cache = wp_cache_get( 'wp_get_archives' , 'general'); 400 if ( !isset( $cache[ $key ] ) ) { 401 $arcresults = $wpdb->get_results($query); 402 $cache[ $key ] = $arcresults; 403 wp_cache_add( 'wp_get_archives', $cache, 'general' ); 404 } else { 405 $arcresults = $cache[ $key ]; 406 } 407 if ( $arcresults ) { 408 $afterafter = $after; 409 foreach ( $arcresults as $arcresult ) { 410 $url = get_month_link($arcresult->year, $arcresult->month); 411 $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($arcresult->month), $arcresult->year); 412 if ( $show_post_count ) 413 $after = ' ('.$arcresult->posts.')' . $afterafter; 414 echo get_archives_link($url, $text, $format, $before, $after); 415 } 416 } 417 } elseif ('yearly' == $type) { 418 $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"; 419 $key = md5($query); 420 $cache = wp_cache_get( 'wp_get_archives' , 'general'); 421 if ( !isset( $cache[ $key ] ) ) { 422 $arcresults = $wpdb->get_results($query); 423 $cache[ $key ] = $arcresults; 424 wp_cache_add( 'wp_get_archives', $cache, 'general' ); 425 } else { 426 $arcresults = $cache[ $key ]; 427 } 428 if ($arcresults) { 429 $afterafter = $after; 430 foreach ($arcresults as $arcresult) { 431 $url = get_year_link($arcresult->year); 432 $text = sprintf('%d', $arcresult->year); 433 if ($show_post_count) 434 $after = ' ('.$arcresult->posts.')' . $afterafter; 435 echo get_archives_link($url, $text, $format, $before, $after); 436 } 437 } 438 } elseif ( 'daily' == $type ) { 439 $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"; 440 $key = md5($query); 441 $cache = wp_cache_get( 'wp_get_archives' , 'general'); 442 if ( !isset( $cache[ $key ] ) ) { 443 $arcresults = $wpdb->get_results($query); 444 $cache[ $key ] = $arcresults; 445 wp_cache_add( 'wp_get_archives', $cache, 'general' ); 446 } else { 447 $arcresults = $cache[ $key ]; 448 } 449 if ( $arcresults ) { 450 $afterafter = $after;