Make WordPress Core

Ticket #4209: 4209-nextgen.diff

File 4209-nextgen.diff, 3.8 KB (added by rob1n, 16 years ago)
  • wp-includes/default-filters.php

     
    160160add_action('wp_head', 'locale_stylesheet');
    161161add_action('publish_future_post', 'wp_publish_post', 10, 1);
    162162add_action('wp_head', 'noindex', 1);
     163add_action( 'wp_head', 'link_rel_prev_next' );
    163164add_action('wp_head', 'wp_print_scripts');
    164165if(!defined('DOING_CRON'))
    165166        add_action('init', 'wp_cron');
  • wp-includes/link-template.php

     
    352352
    353353// Navigation links
    354354
    355 function get_previous_post($in_same_cat = false, $excluded_categories = '') {
    356         global $post, $wpdb;
     355function get_previous_post($in_same_cat = false, $excluded_categories = '', $id = 0) {
     356        global $wpdb;
     357       
     358        $post = &get_post( $id );
    357359
    358360        if( !is_single() || is_attachment() )
    359361                return null;
     
    389391        return @$wpdb->get_row("SELECT ID, post_title FROM $wpdb->posts $join $where $sort");
    390392}
    391393
    392 function get_next_post($in_same_cat = false, $excluded_categories = '') {
    393         global $post, $wpdb;
     394function get_next_post($in_same_cat = false, $excluded_categories = '', $id = 0) {
     395        global $wpdb;
     396       
     397        $post = &get_post( $id );
    394398
    395399        if( !is_single() || is_attachment() )
    396400                return null;
     
    438442                return;
    439443
    440444        $title = apply_filters('the_title', $post->post_title, $post);
    441         $string = '<a href="'.get_permalink($post->ID).'">';
     445        $string = '<a href="'.get_permalink($post->ID).'" rel="prev">';
    442446        $link = str_replace('%title', $title, $link);
    443447        $link = $pre . $string . $link . '</a>';
    444448
     
    454458                return;
    455459
    456460        $title = apply_filters('the_title', $post->post_title, $post);
    457         $string = '<a href="'.get_permalink($post->ID).'">';
     461        $string = '<a href="'.get_permalink($post->ID).'" rel="next">';
    458462        $link = str_replace('%title', $title, $link);
    459463        $link = $string . $link . '</a>';
    460464        $format = str_replace('%link', $link, $format);
     
    607611        }
    608612}
    609613
    610 ?>
     614function link_rel_prev_next( $id = 0 ) {
     615        if ( !is_single() ) {
     616                return;
     617        }
     618       
     619        $prev_url = '';
     620        $next_url = '';
     621       
     622        $post = get_post( $id );
     623        setup_postdata( $post );
     624       
     625        global $multipage, $numpages, $pagenow, $page, $wp_rewrite;
     626       
     627        if ( $multipage ) {
     628                global $numpages, $pagenow, $page;
     629               
     630                if ( $page == 1 ) {
     631                        if ( $prev_post = get_previous_post( false, '', $post->ID ) ) {
     632                                $prev_url = get_permalink( $prev_post->ID );
     633                        }
     634                } else {
     635                        if ( !$wp_rewrite->using_permalinks() || $post->post_status == 'draft' ) {
     636                                $prev_url = add_query_arg( 'page', $page - 1, get_permalink() );
     637                        } else {
     638                                $prev_url = trailingslashit( get_permalink() ) . user_trailingslashit( $page - 1, 'single_paged' );
     639                        }
     640                }
     641               
     642                if ( $page == $numpages ) {
     643                        if ( $next_post = get_next_post( false, '', $post->ID ) ) {
     644                                $next_url = get_permalink( $next_post->ID );
     645                        }
     646                } else {
     647                        if ( !$wp_rewrite->using_permalinks() || $post->post_status == 'draft' ) {
     648                                $next_url = add_query_arg( 'page', $page + 1, get_permalink( $post->ID ) );
     649                        } else {
     650                                $next_url = trailingslashit( get_permalink() ) . user_trailingslashit( $page + 1, 'single_paged' );
     651                        }
     652                }
     653        } else {
     654                if ( $prev_post = get_previous_post( false, '', $post->ID ) ) {
     655                        $prev_url = get_permalink( $prev_post->ID );
     656                }
     657               
     658                if ( $next_post = get_next_post( false, '', $post->ID ) ) {
     659                        $next_url = get_permalink( $next_post->ID );
     660                }
     661        }
     662       
     663        if ( !empty( $prev_url ) ) {
     664                printf( '<link rel="prev" href="%s" />' . "\n", $prev_url );
     665        }
     666       
     667        if ( !empty( $next_url ) ) {
     668                printf( '<link rel="next" href="%s" />' . "\n", $next_url );
     669        }
     670}                       
     671
     672?>
     673 No newline at end of file