Changeset 3655
- Timestamp:
- 03/21/2006 04:26:50 AM (20 years ago)
- Location:
- trunk/wp-includes
- Files:
-
- 4 edited
-
functions.php (modified) (1 diff)
-
template-functions-bookmarks.php (modified) (3 diffs)
-
template-functions-category.php (modified) (2 diffs)
-
template-functions-post.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/functions.php
r3654 r3655 1447 1447 function get_posts($args) { 1448 1448 global $wpdb; 1449 1450 if ( is_array($args) ) 1451 $r = &$args; 1452 else 1453 parse_str($args, $r); 1449 1454 parse_str($args, $r); 1450 if ( !isset($r['numberposts']) ) 1451 $r['numberposts'] = 5; 1452 if ( !isset($r['offset']) ) 1453 $r['offset'] = 0; 1454 if ( !isset($r['category']) ) 1455 $r['category'] = ''; 1456 if ( !isset($r['orderby']) ) 1457 $r['orderby'] = 'post_date'; 1458 if ( !isset($r['order']) ) 1459 $r['order'] = 'DESC'; 1455 1456 $defaults = array('numberposts' => 5, 'offset' => 0, 'category' => '', 1457 'orderby' => 'post_date', 'order' => 'DESC', 'include' => '', 'exclude' => ''); 1458 $r = array_merge($defaults, $r); 1459 extract($r); 1460 1461 $inclusions = ''; 1462 if ( !empty($include) ) { 1463 $offset = 0; //ignore offset, category, and exclude params if using include 1464 $category = ''; 1465 $exclude = ''; 1466 $incposts = preg_split('/[\s,]+/',$include); 1467 $numberposts = count($incposts); // only the number of posts included 1468 if ( count($incposts) ) { 1469 foreach ( $incposts as $incpost ) { 1470 if (empty($inclusions)) 1471 $inclusions = ' AND ( ID = ' . intval($incpost) . ' '; 1472 else 1473 $inclusions .= ' OR ID = ' . intval($incpost) . ' '; 1474 } 1475 } 1476 } 1477 if (!empty($inclusions)) 1478 $inclusions .= ')'; 1479 1480 $exclusions = ''; 1481 if ( !empty($exclude) ) { 1482 $exposts = preg_split('/[\s,]+/',$exclude); 1483 if ( count($exposts) ) { 1484 foreach ( $exposts as $expost ) { 1485 if (empty($exclusions)) 1486 $exclusions = ' AND ( ID <> ' . intval($expost) . ' '; 1487 else 1488 $exclusions .= ' AND ID <> ' . intval($expost) . ' '; 1489 } 1490 } 1491 } 1492 if (!empty($exclusions)) 1493 $exclusions .= ')'; 1460 1494 1461 1495 $posts = $wpdb->get_results( 1462 1496 "SELECT DISTINCT * FROM $wpdb->posts " . 1463 ( empty( $ r['category']) ? "" : ", $wpdb->post2cat " ) .1464 " WHERE (post_type = 'post' AND post_status = 'publish') ".1465 ( empty( $ r['category'] ) ? "" : "AND $wpdb->posts.ID = $wpdb->post2cat.post_id AND $wpdb->post2cat.category_id = " . $r['category']. " " ) .1466 " GROUP BY $wpdb->posts.ID ORDER BY " . $ r['orderby'] . " " . $r['order'] . " LIMIT " . $r['offset'] . ',' . $r['numberposts']);1497 ( empty( $category ) ? "" : ", $wpdb->post2cat " ) . 1498 " WHERE (post_type = 'post' AND post_status = 'publish') $exclusions $inclusions " . 1499 ( empty( $category ) ? "" : "AND $wpdb->posts.ID = $wpdb->post2cat.post_id AND $wpdb->post2cat.category_id = " . $category. " " ) . 1500 " GROUP BY $wpdb->posts.ID ORDER BY " . $orderby . " " . $order . " LIMIT " . $offset . ',' . $numberposts ); 1467 1501 1468 1502 update_post_caches($posts); -
trunk/wp-includes/template-functions-bookmarks.php
r3606 r3655 284 284 285 285 $defaults = array('orderby' => 'name', 'order' => 'ASC', 'limit' => -1, 'category' => -1, 286 'category_name' => '', 'hide_invisible' => 1, 'show_updated' => 0 );286 'category_name' => '', 'hide_invisible' => 1, 'show_updated' => 0, 'include' => '', 'exclude' => ''); 287 287 $r = array_merge($defaults, $r); 288 288 extract($r); 289 289 290 $inclusions = ''; 291 if ( !empty($include) ) { 292 $exclude = ''; //ignore exclude, category, and category_name params if using include 293 $category = -1; 294 $category_name = ''; 295 $inclinks = preg_split('/[\s,]+/',$include); 296 if ( count($inclinks) ) { 297 foreach ( $inclinks as $inclink ) { 298 if (empty($inclusions)) 299 $inclusions = ' AND ( link_id = ' . intval($inclink) . ' '; 300 else 301 $inclusions .= ' OR link_id = ' . intval($inclink) . ' '; 302 } 303 } 304 } 305 if (!empty($inclusions)) 306 $inclusions .= ')'; 307 290 308 $exclusions = ''; 291 309 if ( !empty($exclude) ) { 292 $exlinks = preg_split('/[\s,]+/',$ r['exclude']);310 $exlinks = preg_split('/[\s,]+/',$exclude); 293 311 if ( count($exlinks) ) { 294 312 foreach ( $exlinks as $exlink ) { 295 $exclusions .= ' AND link_id <> ' . intval($exlink) . ' '; 313 if (empty($exclusions)) 314 $exclusions = ' AND ( link_id <> ' . intval($exlink) . ' '; 315 else 316 $exclusions .= ' AND link_id <> ' . intval($exlink) . ' '; 296 317 } 297 318 } 298 319 } 299 320 if (!empty($exclusions)) 321 $exclusions .= ')'; 322 300 323 if ( ! empty($category_name) ) { 301 324 if ( $cat_id = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE cat_name='$category_name' LIMIT 1") ) … … 321 344 } 322 345 323 $orderby = strtolower($ r['orderby']);346 $orderby = strtolower($orderby); 324 347 $length = ''; 325 348 switch ($orderby) { … … 342 365 343 366 $query = "SELECT * $length $recently_updated_test $get_updated FROM $wpdb->links $join WHERE 1=1 $visible $category_query"; 367 $query .= " $exclusions $inclusions"; 344 368 $query .= " ORDER BY $orderby $order"; 345 369 if ($limit != -1) -
trunk/wp-includes/template-functions-category.php
r3605 r3655 377 377 378 378 $defaults = array('type' => 'post', 'child_of' => 0, 'orderby' => 'name', 'order' => 'ASC', 379 'hide_empty' => true, 'include_last_update_time' => false, 'hierarchical' => 1 );379 'hide_empty' => true, 'include_last_update_time' => false, 'hierarchical' => 1, $exclude => '', $include => ''); 380 380 $r = array_merge($defaults, $r); 381 $r['orderby'] = "cat_" . $r['orderby']; 381 $r['orderby'] = "cat_" . $r['orderby']; // restricts order by to cat_ID and cat_name fields 382 382 extract($r); 383 383 384 $exclusions = '';385 $having = '';386 384 $where = 'cat_ID > 0'; 385 $inclusions = ''; 386 if ( !empty($include) ) { 387 $child_of = 0; //ignore child_of and exclude params if using include 388 $exclude = ''; 389 $incategories = preg_split('/[\s,]+/',$include); 390 if ( count($incategories) ) { 391 foreach ( $incategories as $incat ) { 392 if (empty($inclusions)) 393 $inclusions = ' AND ( cat_ID = ' . intval($incat) . ' '; 394 else 395 $inclusions .= ' OR cat_ID = ' . intval($incat) . ' '; 396 } 397 } 398 } 399 if (!empty($inclusions)) 400 $inclusions .= ')'; 401 $where .= $inclusions; 387 402 388 403 $exclusions = ''; … … 391 406 if ( count($excategories) ) { 392 407 foreach ( $excategories as $excat ) { 393 $exclusions .= ' AND cat_ID <> ' . intval($excat) . ' '; 394 // TODO: Exclude children of excluded cats? 408 if (empty($exclusions)) 409 $exclusions = ' AND ( cat_ID <> ' . intval($excat) . ' '; 410 else 411 $exclusions .= ' AND cat_ID <> ' . intval($excat) . ' '; 412 // TODO: Exclude children of excluded cats? Note: children are getting excluded 395 413 } 396 414 } 397 415 } 416 if (!empty($exclusions)) 417 $exclusions .= ')'; 398 418 $exclusions = apply_filters('list_cats_exclusions', $exclusions ); 399 419 $where .= $exclusions; 400 420 421 $having = ''; 401 422 if ( $hide_empty ) { 402 423 if ( 'link' == $type ) -
trunk/wp-includes/template-functions-post.php
r3644 r3655 307 307 308 308 $defaults = array('child_of' => 0, 'sort_order' => 'ASC', 'sort_column' => 'post_title', 309 'hierarchical' => 1 );309 'hierarchical' => 1, $exclude => '', $include => ''); 310 310 $r = array_merge($defaults, $r); 311 extract($r); 312 313 $inclusions = ''; 314 if ( !empty($include) ) { 315 $child_of = 0; //ignore child_of and exclude params if using include 316 $exclude = ''; 317 $incpages = preg_split('/[\s,]+/',$include); 318 if ( count($incpages) ) { 319 foreach ( $incpages as $incpage ) { 320 if (empty($inclusions)) 321 $inclusions = ' AND ( ID = ' . intval($incpage) . ' '; 322 else 323 $inclusions .= ' OR ID = ' . intval($incpage) . ' '; 324 } 325 } 326 } 327 if (!empty($inclusions)) 328 $inclusions .= ')'; 311 329 312 330 $exclusions = ''; 313 if ( !empty($ r['exclude']) ) {314 $expages = preg_split('/[\s,]+/',$ r['exclude']);331 if ( !empty($exclude) ) { 332 $expages = preg_split('/[\s,]+/',$exclude); 315 333 if ( count($expages) ) { 316 334 foreach ( $expages as $expage ) { 317 $exclusions .= ' AND ID <> ' . intval($expage) . ' '; 335 if (empty($exclusions)) 336 $exclusions = ' AND ( ID <> ' . intval($expage) . ' '; 337 else 338 $exclusions .= ' AND ID <> ' . intval($expage) . ' '; 318 339 } 319 340 } 320 341 } 342 if (!empty($exclusions)) 343 $exclusions .= ')'; 321 344 322 345 $pages = $wpdb->get_results("SELECT * " . 323 346 "FROM $wpdb->posts " . 324 347 "WHERE post_type = 'page' AND post_status = 'publish' " . 325 "$exclusions " .326 "ORDER BY " . $ r['sort_column'] . " " . $r['sort_order']);348 "$exclusions $inclusions" . 349 "ORDER BY " . $sort_column . " " . $sort_order); 327 350 328 351 if ( empty($pages) ) … … 332 355 update_page_cache($pages); 333 356 334 if ( $ r['child_of'] || $r['hierarchical'])335 $pages = & get_page_children($ r['child_of'], $pages);357 if ( $child_of || $hierarchical ) 358 $pages = & get_page_children($child_of, $pages); 336 359 337 360 return $pages;
Note: See TracChangeset
for help on using the changeset viewer.