Changeset 1383 for trunk/wp-includes/template-functions-post.php
- Timestamp:
- 06/02/2004 07:44:43 AM (22 years ago)
- File:
-
- 1 edited
-
trunk/wp-includes/template-functions-post.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/template-functions-post.php
r1373 r1383 274 274 } 275 275 276 277 function previous_post($format='%', $previous='previous post: ', $title='yes', $in_same_cat='no', $limitprev=1, $excluded_categories='') {278 global $id, $post, $wpdb;279 global $p, $posts, $posts_per_page, $s, $single;280 global $querystring_start, $querystring_equal, $querystring_separator;281 282 if(($p) || ($posts_per_page == 1) || 1 == $single) {283 284 $current_post_date = $post->post_date;285 $current_category = $post->post_category;286 287 $sqlcat = '';288 if ($in_same_cat != 'no') {289 $sqlcat = " AND post_category = '$current_category' ";290 }291 292 $sql_exclude_cats = '';293 if (!empty($excluded_categories)) {294 $blah = explode('and', $excluded_categories);295 foreach($blah as $category) {296 $category = intval($category);297 $sql_exclude_cats .= " AND post_category != $category";298 }299 }300 301 $limitprev--;302 $lastpost = @$wpdb->get_row("SELECT ID, post_title FROM $wpdb->posts WHERE post_date < '$current_post_date' AND post_status = 'publish' $sqlcat $sql_exclude_cats ORDER BY post_date DESC LIMIT $limitprev, 1");303 if ($lastpost) {304 $string = '<a href="'.get_permalink($lastpost->ID).'">'.$previous;305 if ($title == 'yes') {306 $string .= wptexturize(stripslashes($lastpost->post_title));307 }308 $string .= '</a>';309 $format = str_replace('%', $string, $format);310 echo $format;311 }312 }313 }314 315 function next_post($format='%', $next='next post: ', $title='yes', $in_same_cat='no', $limitnext=1, $excluded_categories='') {316 global $posts_per_page, $post, $wpdb, $single;317 if(1 == $posts_per_page || 1 == $single) {318 319 $current_post_date = $post->post_date;320 $current_category = $post->post_category;321 322 $sqlcat = '';323 if ($in_same_cat != 'no') {324 $sqlcat = " AND post_category='$current_category' ";325 }326 327 $sql_exclude_cats = '';328 if (!empty($excluded_categories)) {329 $blah = explode('and', $excluded_categories);330 foreach($blah as $category) {331 $category = intval($category);332 $sql_exclude_cats .= " AND post_category != $category";333 }334 }335 336 $now = current_time('mysql');337 338 $limitnext--;339 340 $nextpost = @$wpdb->get_row("SELECT ID,post_title FROM $wpdb->posts WHERE post_date > '$current_post_date' AND post_date < '$now' AND post_status = 'publish' $sqlcat $sql_exclude_cats AND ID != $post->ID ORDER BY post_date ASC LIMIT $limitnext,1");341 if ($nextpost) {342 $string = '<a href="'.get_permalink($nextpost->ID).'">'.$next;343 if ($title=='yes') {344 $string .= wptexturize(stripslashes($nextpost->post_title));345 }346 $string .= '</a>';347 $format = str_replace('%', $string, $format);348 echo $format;349 }350 }351 }352 353 function get_pagenum_link($pagenum = 1){354 $qstr = $_SERVER['REQUEST_URI'];355 356 $page_querystring = "paged";357 $page_modstring = "page/";358 $page_modregex = "page/?";359 360 // if we already have a QUERY style page string361 if( stristr( $qstr, $page_querystring ) ) {362 $replacement = "$page_querystring=$pagenum";363 $qstr = preg_replace("/".$page_querystring."[^\d]+\d+/", $replacement, $qstr);364 // if we already have a mod_rewrite style page string365 } elseif ( preg_match( '|'.$page_modregex.'\d+|', $qstr ) ){366 $qstr = preg_replace('|'.$page_modregex.'\d+|',"$page_modstring$pagenum",$qstr);367 368 // if we don't have a page string at all ...369 // lets see what sort of URL we have...370 } else {371 // we need to know the way queries are being written372 global $querystring_start, $querystring_equal, $querystring_separator;373 // if there's a querystring_start (a "?" usually), it's deffinitely not mod_rewritten374 if ( stristr( $qstr, $querystring_start ) ){375 // so append the query string (using &, since we already have ?)376 $qstr .= $querystring_separator.$page_querystring.$querystring_equal.$pagenum;377 // otherwise, it could be rewritten, OR just the default index ...378 } elseif( '' != get_settings('permalink_structure')) {379 $qstr = preg_replace('|(.*)/[^/]*|', '$1/', $qstr).$page_modstring.$pagenum;380 } else {381 $qstr = get_settings('blogfilename') . $querystring_start.$page_querystring.$querystring_equal.$pagenum;382 }383 }384 385 $home_root = str_replace('http://', '', trim(get_settings('home')));386 $home_root = preg_replace('|([^/]*)(.*)|i', '$2', $home_root);387 if ('/' != substr($home_root, -1)) $home_root = $home_root . '/';388 389 $qstr = str_replace($home_root, '', $qstr);390 return trailingslashit(get_settings('home')).$qstr;391 }392 393 function next_posts($max_page = 0) { // original by cfactor at cooltux.org394 global $p, $paged, $what_to_show, $pagenow;395 global $querystring_start, $querystring_equal, $querystring_separator;396 // if (empty($p) && ($what_to_show == 'paged')) {397 // $qstr = $_SERVER['QUERY_STRING'];398 // if (!empty($qstr)) {399 // $qstr = preg_replace('/&paged=\d{0,}/', '', $qstr);400 // $qstr = preg_replace('/paged=\d{0,}/', '', $qstr);401 // } elseif (stristr($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME'] )) {402 // if ('' != $qstr = str_replace($_SERVER['SCRIPT_NAME'], '',403 // $_SERVER['REQUEST_URI']) ) {404 // $qstr = preg_replace('/^\//', '', $qstr);405 // $qstr = preg_replace('/paged\/\d{0,}\//', '', $qstr);406 // $qstr = preg_replace('/paged\/\d{0,}/', '', $qstr);407 // $qstr = preg_replace('/\/$/', '', $qstr);408 // }409 // }410 // if (!$paged) $paged = 1;411 // $nextpage = intval($paged) + 1;412 // if (!$max_page || $max_page >= $nextpage) {413 // echo get_settings('home') .'/'.$pagenow.$querystring_start.414 // ($qstr == '' ? '' : $qstr.$querystring_separator) .415 // 'paged'.$querystring_equal.$nextpage;416 // }417 // }418 419 if (empty($p) && ($what_to_show == 'paged')) {420 if (!$paged) $paged = 1;421 $nextpage = intval($paged) + 1;422 if (!$max_page || $max_page >= $nextpage) {423 echo get_pagenum_link($nextpage);424 }425 }426 }427 428 function next_posts_link($label='Next Page »', $max_page=0) {429 global $p, $paged, $result, $request, $posts_per_page, $what_to_show, $wpdb;430 if ($what_to_show == 'paged') {431 if (!$max_page) {432 $nxt_request = $request;433 //if the query includes a limit clause, call it again without that434 //limit clause!435 if ($pos = strpos(strtoupper($request), 'LIMIT')) {436 $nxt_request = substr($request, 0, $pos);437 }438 $nxt_result = $wpdb->query($nxt_request);439 $numposts = $wpdb->num_rows;440 $max_page = ceil($numposts / $posts_per_page);441 }442 if (!$paged)443 $paged = 1;444 $nextpage = intval($paged) + 1;445 if (empty($p) && (empty($paged) || $nextpage <= $max_page)) {446 echo '<a href="';447 next_posts($max_page);448 echo '">'. preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>';449 }450 }451 }452 453 454 function previous_posts() { // original by cfactor at cooltux.org455 global $_SERVER, $p, $paged, $what_to_show, $pagenow;456 global $querystring_start, $querystring_equal, $querystring_separator;457 // if (empty($p) && ($what_to_show == 'paged')) {458 // $qstr = $_SERVER['QUERY_STRING'];459 // if (!empty($qstr)) {460 // $qstr = preg_replace('/&paged=\d{0,}/', '', $qstr);461 // $qstr = preg_replace('/paged=\d{0,}/', '', $qstr);462 // } elseif (stristr($_SERVER['REQUEST_URI'], $_SERVER['SCRIPT_NAME'] )) {463 // if ('' != $qstr = str_replace($_SERVER['SCRIPT_NAME'], '',464 // $_SERVER['REQUEST_URI']) ) {465 // $qstr = preg_replace('/^\//', '', $qstr);466 // $qstr = preg_replace("/paged\/\d{0,}\//", '', $qstr);467 // $qstr = preg_replace('/paged\/\d{0,}/', '', $qstr);468 // $qstr = preg_replace('/\/$/', '', $qstr);469 // }470 // }471 // $nextpage = intval($paged) - 1;472 // if ($nextpage < 1) $nextpage = 1;473 // echo get_settings('home') .'/'.$pagenow.$querystring_start.474 // ($qstr == '' ? '' : $qstr.$querystring_separator) .475 // 'paged'.$querystring_equal.$nextpage;476 // }477 478 if (empty($p) && ($what_to_show == 'paged')) {479 $nextpage = intval($paged) - 1;480 if ($nextpage < 1) $nextpage = 1;481 echo get_pagenum_link($nextpage);482 }483 }484 485 function previous_posts_link($label='« Previous Page') {486 global $p, $paged, $what_to_show;487 if (empty($p) && ($paged > 1) && ($what_to_show == 'paged')) {488 echo '<a href="';489 previous_posts();490 echo '">'. preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $label) .'</a>';491 }492 }493 494 function posts_nav_link($sep=' :: ', $prelabel='<< Previous Page', $nxtlabel='Next Page >>') {495 global $p, $what_to_show, $request, $posts_per_page, $wpdb;496 if (empty($p) && ($what_to_show == 'paged')) {497 $nxt_request = $request;498 if ($pos = strpos(strtoupper($request), 'LIMIT')) {499 $nxt_request = substr($request, 0, $pos);500 }501 $nxt_result = $wpdb->query($nxt_request);502 $numposts = $wpdb->num_rows;503 $max_page = ceil($numposts / $posts_per_page);504 if ($max_page > 1) {505 previous_posts_link($prelabel);506 echo preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', $sep);507 next_posts_link($nxtlabel, $max_page);508 }509 }510 }511 512 276 /* 513 277 * Post-meta: Custom per-post fields.
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)