Changeset 18477
- Timestamp:
- 07/28/2011 05:19:51 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/link-template.php
r18328 r18477 1066 1066 * 1067 1067 * @param bool $in_same_cat Optional. Whether post should be in same category. 1068 * @param string $excluded_categories Optional. Excluded categoriesIDs.1068 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 1069 1069 * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists. 1070 1070 */ … … 1079 1079 * 1080 1080 * @param bool $in_same_cat Optional. Whether post should be in same category. 1081 * @param string $excluded_categories Optional. Excluded categoriesIDs.1081 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 1082 1082 * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists. 1083 1083 */ … … 1094 1094 * 1095 1095 * @param bool $in_same_cat Optional. Whether post should be in same category. 1096 * @param string $excluded_categories Optional. Excluded categoriesIDs.1096 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 1097 1097 * @param bool $previous Optional. Whether to retrieve previous post. 1098 1098 * @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists. 1099 1099 */ 1100 function get_adjacent_post( $in_same_cat = false, $excluded_categories = '', $previous = true) {1100 function get_adjacent_post( $in_same_cat = false, $excluded_categories = '', $previous = true ) { 1101 1101 global $post, $wpdb; 1102 1102 … … 1108 1108 $join = ''; 1109 1109 $posts_in_ex_cats_sql = ''; 1110 if ( $in_same_cat || ! empty($excluded_categories) ) {1110 if ( $in_same_cat || ! empty( $excluded_categories ) ) { 1111 1111 $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 1112 … … 1117 1117 1118 1118 $posts_in_ex_cats_sql = "AND tt.taxonomy = 'category'"; 1119 if ( !empty($excluded_categories) ) { 1120 $excluded_categories = array_map('intval', explode(' and ', $excluded_categories)); 1121 if ( !empty($cat_array) ) { 1119 if ( ! empty( $excluded_categories ) ) { 1120 if ( ! is_array( $excluded_categories ) ) { 1121 // back-compat, $excluded_categories used to be IDs separated by " and " 1122 if ( strpos( $excluded_categories, ' and ' ) !== false ) 1123 $excluded_categories = explode( ' and ', $excluded_categories ); 1124 else 1125 $excluded_categories = explode( ',', $excluded_categories ); 1126 } 1127 1128 $excluded_categories = array_map( 'intval', $excluded_categories ); 1129 1130 if ( ! empty( $cat_array ) ) { 1122 1131 $excluded_categories = array_diff($excluded_categories, $cat_array); 1123 1132 $posts_in_ex_cats_sql = ''; … … 1161 1170 * @param string $title Optional. Link title format. 1162 1171 * @param bool $in_same_cat Optional. Whether link should be in same category. 1163 * @param string $excluded_categories Optional. Excluded categoriesIDs.1172 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 1164 1173 * @param bool $previous Optional, default is true. Whether display link to previous post. 1165 1174 * @return string … … 1198 1207 * @param string $title Optional. Link title format. 1199 1208 * @param bool $in_same_cat Optional. Whether link should be in same category. 1200 * @param string $excluded_categories Optional. Excluded categoriesIDs.1209 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 1201 1210 */ 1202 1211 function adjacent_posts_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') { … … 1225 1234 * @param string $title Optional. Link title format. 1226 1235 * @param bool $in_same_cat Optional. Whether link should be in same category. 1227 * @param string $excluded_categories Optional. Excluded categoriesIDs.1236 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 1228 1237 */ 1229 1238 function next_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') { … … 1238 1247 * @param string $title Optional. Link title format. 1239 1248 * @param bool $in_same_cat Optional. Whether link should be in same category. 1240 * @param string $excluded_categories Optional. Excluded categoriesIDs.1249 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 1241 1250 */ 1242 1251 function prev_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') { … … 1253 1262 * 1254 1263 * @param bool $in_same_cat Optional. Whether returned post should be in same category. 1255 * @param string $excluded_categories Optional. Excluded categoriesIDs.1264 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 1256 1265 * @param bool $start Optional. Whether to retrieve first or last post. 1257 1266 * @return object 1258 1267 */ 1259 function get_boundary_post( $in_same_cat = false, $excluded_categories = '', $start = true) {1268 function get_boundary_post( $in_same_cat = false, $excluded_categories = '', $start = true ) { 1260 1269 global $post; 1261 1270 1262 if ( empty($post) || ! is_single() || is_attachment() )1271 if ( empty($post) || ! is_single() || is_attachment() ) 1263 1272 return null; 1264 1273 1265 1274 $cat_array = array(); 1266 $excluded_categories = array(); 1267 if ( !empty($in_same_cat) || !empty($excluded_categories) ) { 1268 if ( !empty($in_same_cat) ) { 1269 $cat_array = wp_get_object_terms($post->ID, 'category', array('fields' => 'ids')); 1270 } 1271 1272 if ( !empty($excluded_categories) ) { 1273 $excluded_categories = array_map('intval', explode(',', $excluded_categories)); 1274 1275 if ( !empty($cat_array) ) 1276 $excluded_categories = array_diff($excluded_categories, $cat_array); 1275 if( ! is_array( $excluded_categories ) ) 1276 $excluded_categories = explode( ',', $excluded_categories ); 1277 1278 if ( $in_same_cat || ! empty( $excluded_categories ) ) { 1279 if ( $in_same_cat ) 1280 $cat_array = wp_get_object_terms( $post->ID, 'category', array( 'fields' => 'ids' ) ); 1281 1282 if ( ! empty( $excluded_categories ) ) { 1283 $excluded_categories = array_map( 'intval', $excluded_categories ); 1284 $excluded_categories = array_diff( $excluded_categories, $cat_array ); 1277 1285 1278 1286 $inverse_cats = array(); 1279 foreach ( $excluded_categories as $excluded_category )1287 foreach ( $excluded_categories as $excluded_category ) 1280 1288 $inverse_cats[] = $excluded_category * -1; 1281 1289 $excluded_categories = $inverse_cats; … … 1283 1291 } 1284 1292 1285 $categories = implode( ',', array_merge($cat_array, $excluded_categories) );1293 $categories = implode( ',', array_merge( $cat_array, $excluded_categories ) ); 1286 1294 1287 1295 $order = $start ? 'ASC' : 'DESC'; … … 1299 1307 * @param string $title Optional. Link title format. 1300 1308 * @param bool $in_same_cat Optional. Whether link should be in same category. 1301 * @param string $excluded_categories Optional. Excluded categoriesIDs.1309 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 1302 1310 * @param bool $start Optional, default is true. Whether display link to first or last post. 1303 1311 * @return string … … 1336 1344 * @param string $title Optional. Link title format. 1337 1345 * @param bool $in_same_cat Optional. Whether link should be in same category. 1338 * @param string $excluded_categories Optional. Excluded categoriesIDs.1346 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 1339 1347 */ 1340 1348 function start_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') { … … 1408 1416 * @param string $link Optional. Link permalink format. 1409 1417 * @param bool $in_same_cat Optional. Whether link should be in same category. 1410 * @param string $excluded_categories Optional. Excluded categoriesIDs.1418 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 1411 1419 */ 1412 1420 function previous_post_link($format='« %link', $link='%title', $in_same_cat = false, $excluded_categories = '') { … … 1422 1430 * @param string $link Optional. Link permalink format. 1423 1431 * @param bool $in_same_cat Optional. Whether link should be in same category. 1424 * @param string $excluded_categories Optional. Excluded categoriesIDs.1432 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 1425 1433 */ 1426 1434 function next_post_link($format='%link »', $link='%title', $in_same_cat = false, $excluded_categories = '') { … … 1438 1446 * @param string $link Link permalink format. 1439 1447 * @param bool $in_same_cat Optional. Whether link should be in same category. 1440 * @param string $excluded_categories Optional. Excluded categoriesIDs.1448 * @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. 1441 1449 * @param bool $previous Optional, default is true. Whether display link to previous post. 1442 1450 */
Note: See TracChangeset
for help on using the changeset viewer.