Stimmt, funktioniert wie es soll. Ich war nur irritiert, dass unten kein "Ältere Beiträge" erscheint, sondern nur oben :confused: .
Danke für deine Mühen zu 3., aber wo sind denn die SQLs?
Zu 1.) habe ich jetzt dank dir mein link-template.php so umgeschrieben (function get_adjacent_post):
Usrprünglich:
PHP
function get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = true) {
global $post, $wpdb;
if( empty($post) || !is_single() || is_attachment() )
return null;
$current_post_date = $post->post_date;
$join = '';
$posts_in_ex_cats_sql = '';
if ( $in_same_cat || !empty($excluded_categories) ) {
$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";
if ( $in_same_cat ) {
$cat_array = wp_get_object_terms($post->ID, 'category', 'fields=ids');
$join .= " AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode($cat_array, ',') . ')';
}
$posts_in_ex_cats_sql = "AND tt.taxonomy = 'category'";
if ( !empty($excluded_categories) ) {
$excluded_categories = array_map('intval', explode(' and ', $excluded_categories));
if ( !empty($cat_array) ) {
$excluded_categories = array_diff($excluded_categories, $cat_array);
$posts_in_ex_cats_sql = '';
}
if ( !empty($excluded_categories) ) {
$posts_in_ex_cats_sql = " AND tt.taxonomy = 'category' AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')';
}
}
}
$adjacent = $previous ? 'previous' : 'next';
$op = $previous ? '<' : '>';
$order = $previous ? 'DESC' : 'ASC';
$join = apply_filters( "get_{$adjacent}_post_join", $join, $in_same_cat, $excluded_categories );
$where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare("WHERE p.post_date $op %s AND p.post_type = 'post' AND p.post_status = 'publish' $posts_in_ex_cats_sql", $current_post_date), $in_same_cat, $excluded_categories );
$sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1" );
return $wpdb->get_row("SELECT p.* FROM $wpdb->posts AS p $join $where $sort");
}
Alles anzeigen
Jetzt:
PHP
function get_adjacent_post($in_same_cat = false, $excluded_categories = '', $previous = true) {
global $post, $wpdb;
if( empty($post) || !is_single() || is_attachment() )
return null;
$current_post_date = $post->post_date;
$current_post_title = $post->post_title;
$join = '';
$posts_in_ex_cats_sql = '';
if ( $in_same_cat || !empty($excluded_categories) ) {
$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";
if ( $in_same_cat ) {
$cat_array = wp_get_object_terms($post->ID, 'category', 'fields=ids');
$join .= " AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode($cat_array, ',') . ')';
}
$posts_in_ex_cats_sql = "AND tt.taxonomy = 'category'";
if ( !empty($excluded_categories) ) {
$excluded_categories = array_map('intval', explode(' and ', $excluded_categories));
if ( !empty($cat_array) ) {
$excluded_categories = array_diff($excluded_categories, $cat_array);
$posts_in_ex_cats_sql = '';
}
if ( !empty($excluded_categories) ) {
$posts_in_ex_cats_sql = " AND tt.taxonomy = 'category' AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')';
}
}
}
$adjacent = $previous ? 'previous' : 'next';
$op = $previous ? '<' : '>';
$order = $previous ? 'DESC' : 'ASC';
$join = apply_filters( "get_{$adjacent}_post_join", $join, $in_same_cat, $excluded_categories );
$where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare("WHERE p.post_title $op '$current_post_title' AND p.post_type = 'post' AND p.post_status = 'publish' $posts_in_ex_cats_sql", $current_post_date), $in_same_cat, $excluded_categories );
$sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_title $order LIMIT 1" );
return $wpdb->get_row("SELECT p.* FROM $wpdb->posts AS p $join $where $sort");
}
Alles anzeigen
Es scheint zu funktionieren,. Mir wäre aber lieb, wenn da nochmal ein "Experte" drüber schauen könnte, nicht dass ich hier groben Unfug anstelle :oops: . Meine Änderungen:
1.) neue Variable => current_post_title
2.) anpassen von $where
3.) anpassen von $sort
Danke und Gruß
Stefan