Ticket #17807: 17807.3.patch
File 17807.3.patch, 12.7 KB (added by , 13 years ago) |
---|
-
wp-includes/link-template.php
1066 1066 * 1067 1067 * @param bool $in_same_cat Optional. Whether post should be in same category. 1068 1068 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 1069 * @param string $taxonomy Optional. Which taxonomy to use. 1069 1070 * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists. 1070 1071 */ 1071 function get_previous_post($in_same_cat = false, $excluded_categories = '' ) {1072 return get_adjacent_post($in_same_cat, $excluded_categories );1072 function get_previous_post($in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') { 1073 return get_adjacent_post($in_same_cat, $excluded_categories, true, $taxonomy); 1073 1074 } 1074 1075 1075 1076 /** … … 1079 1080 * 1080 1081 * @param bool $in_same_cat Optional. Whether post should be in same category. 1081 1082 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 1083 * @param string $taxonomy Optional. Which taxonomy to use. 1082 1084 * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists. 1083 1085 */ 1084 function get_next_post($in_same_cat = false, $excluded_categories = '' ) {1085 return get_adjacent_post($in_same_cat, $excluded_categories, false );1086 function get_next_post($in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') { 1087 return get_adjacent_post($in_same_cat, $excluded_categories, false, $taxonomy); 1086 1088 } 1087 1089 1088 1090 /** … … 1095 1097 * @param bool $in_same_cat Optional. Whether post should be in same category. 1096 1098 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 1097 1099 * @param bool $previous Optional. Whether to retrieve previous post. 1100 * @param string $taxonomy Optional. Which taxonomy to use. 1098 1101 * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists. 1099 1102 */ 1100 function get_adjacent_post( $in_same_cat = false, $excluded_categories = '', $previous = true ) {1103 function get_adjacent_post( $in_same_cat = false, $excluded_categories = '', $previous = true, $taxonomy = 'category' ) { 1101 1104 global $post, $wpdb; 1102 1105 1103 1106 if ( empty( $post ) ) … … 1111 1114 $join = " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id"; 1112 1115 1113 1116 if ( $in_same_cat ) { 1114 $cat_array = wp_get_object_terms($post->ID, 'category', array('fields' => 'ids'));1115 $join .= " AND tt.taxonomy = ' category' AND tt.term_id IN (" . implode(',', $cat_array) . ")";1117 $cat_array = wp_get_object_terms($post->ID, $taxonomy, array('fields' => 'ids')); 1118 $join .= " AND tt.taxonomy = '$taxonomy' AND tt.term_id IN (" . implode(',', $cat_array) . ")"; 1116 1119 } 1117 1120 1118 $posts_in_ex_cats_sql = "AND tt.taxonomy = ' category'";1121 $posts_in_ex_cats_sql = "AND tt.taxonomy = '$taxonomy'"; 1119 1122 if ( ! empty( $excluded_categories ) ) { 1120 1123 if ( ! is_array( $excluded_categories ) ) { 1121 1124 // back-compat, $excluded_categories used to be IDs separated by " and " … … 1135 1138 } 1136 1139 1137 1140 if ( !empty($excluded_categories) ) { 1138 $posts_in_ex_cats_sql = " AND tt.taxonomy = ' category' AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')';1141 $posts_in_ex_cats_sql = " AND tt.taxonomy = '$taxonomy' AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')'; 1139 1142 } 1140 1143 } 1141 1144 } … … 1173 1176 * @param bool $in_same_cat Optional. Whether link should be in same category. 1174 1177 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 1175 1178 * @param bool $previous Optional, default is true. Whether display link to previous post. 1179 * @param string $taxonomy Optional. Which taxonomy to use. 1176 1180 * @return string 1177 1181 */ 1178 function get_adjacent_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $previous = true ) {1182 function get_adjacent_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $previous = true, $taxonomy = 'category') { 1179 1183 if ( $previous && is_attachment() && is_object( $GLOBALS['post'] ) ) 1180 1184 $post = & get_post($GLOBALS['post']->post_parent); 1181 1185 else 1182 $post = get_adjacent_post( $in_same_cat,$excluded_categories,$previous);1186 $post = get_adjacent_post( $in_same_cat, $excluded_categories, $previous, $taxonomy ); 1183 1187 1184 1188 if ( empty($post) ) 1185 1189 return; … … 1209 1213 * @param string $title Optional. Link title format. 1210 1214 * @param bool $in_same_cat Optional. Whether link should be in same category. 1211 1215 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 1216 * @param string $taxonomy Optional. Which taxonomy to use. 1212 1217 */ 1213 function adjacent_posts_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '' ) {1214 echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true );1215 echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false );1218 function adjacent_posts_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') { 1219 echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true, $taxonomy); 1220 echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false, $taxonomy); 1216 1221 } 1217 1222 1218 1223 /** … … 1236 1241 * @param string $title Optional. Link title format. 1237 1242 * @param bool $in_same_cat Optional. Whether link should be in same category. 1238 1243 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 1244 * @param string $taxonomy Optional. Which taxonomy to use. 1239 1245 */ 1240 function next_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '' ) {1241 echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false );1246 function next_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') { 1247 echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false, $taxonomy); 1242 1248 } 1243 1249 1244 1250 /** … … 1249 1255 * @param string $title Optional. Link title format. 1250 1256 * @param bool $in_same_cat Optional. Whether link should be in same category. 1251 1257 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 1258 * @param string $taxonomy Optional. Which taxonomy to use. 1252 1259 */ 1253 function prev_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '' ) {1254 echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true );1260 function prev_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') { 1261 echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true, $taxonomy); 1255 1262 } 1256 1263 1257 1264 /** … … 1265 1272 * @param bool $in_same_cat Optional. Whether returned post should be in same category. 1266 1273 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 1267 1274 * @param bool $start Optional. Whether to retrieve first or last post. 1275 * @param string $taxonomy Optional. Which taxonomy to use. 1268 1276 * @return object 1269 1277 */ 1270 function get_boundary_post( $in_same_cat = false, $excluded_categories = '', $start = true ) {1278 function get_boundary_post( $in_same_cat = false, $excluded_categories = '', $start = true, $taxonomy = 'category' ) { 1271 1279 global $post; 1272 1280 1273 1281 if ( empty($post) || ! is_single() || is_attachment() ) … … 1279 1287 1280 1288 if ( $in_same_cat || ! empty( $excluded_categories ) ) { 1281 1289 if ( $in_same_cat ) 1282 $cat_array = wp_get_object_terms( $post->ID, 'category', array( 'fields' => 'ids' ) );1290 $cat_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) ); 1283 1291 1284 1292 if ( ! empty( $excluded_categories ) ) { 1285 1293 $excluded_categories = array_map( 'intval', $excluded_categories ); … … 1295 1303 $categories = implode( ',', array_merge( $cat_array, $excluded_categories ) ); 1296 1304 1297 1305 $order = $start ? 'ASC' : 'DESC'; 1306 1307 $args = array( 1308 'posts_per_page' => '1', 1309 'order' => $order, 1310 'update_post_term_cache' => false, 1311 'update_post_meta_cache' => false, 1312 'tax_query' => array( 1313 array( 1314 'taxonomy' => $taxonomy, 1315 'field' => 'id', 1316 'terms' => $categories 1317 ) 1318 ) 1319 1320 ); 1298 1321 1299 return get_posts( array('numberposts' => 1, 'category' => $categories, 'order' => $order, 'update_post_term_cache' => false, 'update_post_meta_cache' => false));1322 return get_posts( $args ); 1300 1323 } 1301 1324 1302 1325 /** … … 1310 1333 * @param bool $in_same_cat Optional. Whether link should be in same category. 1311 1334 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 1312 1335 * @param bool $start Optional, default is true. Whether display link to first or last post. 1336 * @param string $taxonomy Optional. Which taxonomy to use. 1313 1337 * @return string 1314 1338 */ 1315 function get_boundary_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $start = true ) {1316 $posts = get_boundary_post($in_same_cat, $excluded_categories, $start );1339 function get_boundary_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $start = true, $taxonomy = 'category') { 1340 $posts = get_boundary_post($in_same_cat, $excluded_categories, $start, $taxonomy); 1317 1341 // If there is no post stop. 1318 1342 if ( empty($posts) ) 1319 1343 return; … … 1346 1370 * @param string $title Optional. Link title format. 1347 1371 * @param bool $in_same_cat Optional. Whether link should be in same category. 1348 1372 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 1373 * @param string $taxonomy Optional. Which taxonomy to use. 1349 1374 */ 1350 function start_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '' ) {1351 echo get_boundary_post_rel_link($title, $in_same_cat, $excluded_categories, true );1375 function start_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') { 1376 echo get_boundary_post_rel_link($title, $in_same_cat, $excluded_categories, true, $taxonomy); 1352 1377 } 1353 1378 1354 1379 /** … … 1418 1443 * @param string $link Optional. Link permalink format. 1419 1444 * @param bool $in_same_cat Optional. Whether link should be in same category. 1420 1445 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 1446 * @param string $taxonomy Optional. Which taxonomy to use. 1421 1447 */ 1422 function previous_post_link($format='« %link', $link='%title', $in_same_cat = false, $excluded_categories = '' ) {1423 adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, true );1448 function previous_post_link($format='« %link', $link='%title', $in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') { 1449 adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, true, $taxonomy); 1424 1450 } 1425 1451 1426 1452 /** … … 1432 1458 * @param string $link Optional. Link permalink format. 1433 1459 * @param bool $in_same_cat Optional. Whether link should be in same category. 1434 1460 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 1461 * @param string $taxonomy Optional. Which taxonomy to use. 1435 1462 */ 1436 function next_post_link($format='%link »', $link='%title', $in_same_cat = false, $excluded_categories = '' ) {1437 adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, false );1463 function next_post_link($format='%link »', $link='%title', $in_same_cat = false, $excluded_categories = '', $taxonomy = 'category') { 1464 adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, false, $taxonomy); 1438 1465 } 1439 1466 1440 1467 /** … … 1449 1476 * @param bool $in_same_cat Optional. Whether link should be in same category. 1450 1477 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 1451 1478 * @param bool $previous Optional, default is true. Whether display link to previous post. 1479 * @param string $taxonomy Optional. Which taxonomy to use. 1452 1480 */ 1453 function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true ) {1481 function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true, $taxonomy = 'category') { 1454 1482 if ( $previous && is_attachment() ) 1455 1483 $post = & get_post($GLOBALS['post']->post_parent); 1456 1484 else 1457 $post = get_adjacent_post($in_same_cat, $excluded_categories, $previous );1485 $post = get_adjacent_post($in_same_cat, $excluded_categories, $previous, $taxonomy); 1458 1486 1459 1487 if ( !$post ) 1460 1488 return; … … 2485 2513 } 2486 2514 } 2487 2515 2488 ?> 2516 ?> 2517 No newline at end of file