1908 | | /* |
1909 | | * If 'page' or 'per_page' has been passed, and does not match what's in $wp_query, |
1910 | | * perform a separate comment query and allow Walker_Comment to paginate. |
1911 | | */ |
1912 | | if ( is_singular() && ( $r['page'] || $r['per_page'] ) ) { |
1913 | | $current_cpage = get_query_var( 'cpage' ); |
1914 | | if ( ! $current_cpage ) { |
1915 | | $current_cpage = 'newest' === get_option( 'default_comments_page' ) ? 1 : $wp_query->max_num_comment_pages; |
1916 | | } |
1917 | | |
1918 | | $current_per_page = get_query_var( 'comments_per_page' ); |
1919 | | if ( $r['page'] != $current_cpage || $r['per_page'] != $current_per_page ) { |
1920 | | $comments = get_comments( array( |
1921 | | 'post_id' => get_queried_object_id(), |
1922 | | 'orderby' => 'comment_date_gmt', |
1923 | | 'order' => 'ASC', |
1924 | | 'status' => 'all', |
1925 | | ) ); |
1926 | | } |
1927 | | } |
1928 | | |
1943 | | if ( empty($wp_query->comments) ) |
1944 | | return; |
1945 | | if ( 'all' != $r['type'] ) { |
1946 | | if ( empty($wp_query->comments_by_type) ) |
1947 | | $wp_query->comments_by_type = separate_comments($wp_query->comments); |
1948 | | if ( empty($wp_query->comments_by_type[$r['type']]) ) |
1949 | | return; |
1950 | | $_comments = $wp_query->comments_by_type[$r['type']]; |
1951 | | } else { |
1952 | | $_comments = $wp_query->comments; |
1953 | | } |
| 1922 | /* |
| 1923 | * If 'page' or 'per_page' has been passed, and does not match what's in $wp_query, |
| 1924 | * perform a separate comment query and allow Walker_Comment to paginate. |
| 1925 | */ |
| 1926 | if ( is_singular() && ( $r['page'] || $r['per_page'] ) ) { |
| 1927 | $current_cpage = get_query_var( 'cpage' ); |
| 1928 | if ( ! $current_cpage ) { |
| 1929 | $current_cpage = 'newest' === get_option( 'default_comments_page' ) ? 1 : $wp_query->max_num_comment_pages; |
| 1930 | } |
1955 | | // Pagination is already handled by `WP_Comment_Query`, so we tell Walker not to bother. |
1956 | | if ( $wp_query->max_num_comment_pages ) { |
1957 | | $default_comments_page = get_option( 'default_comments_page' ); |
1958 | | $cpage = get_query_var( 'cpage' ); |
1959 | | if ( 'newest' === $default_comments_page ) { |
1960 | | $r['cpage'] = $cpage; |
| 1932 | $current_per_page = get_query_var( 'comments_per_page' ); |
| 1933 | if ( $r['page'] != $current_cpage || $r['per_page'] != $current_per_page ) { |
| 1934 | $comments = get_comments( array( |
| 1935 | 'post_id' => get_queried_object_id(), |
| 1936 | 'orderby' => 'comment_date_gmt', |
| 1937 | 'order' => 'ASC', |
| 1938 | 'status' => 'all', |
| 1939 | ) ); |
1962 | | // When first page shows oldest comments, post permalink is the same as the comment permalink. |
1963 | | } elseif ( $cpage == 1 ) { |
1964 | | $r['cpage'] = ''; |
| 1941 | if ( 'all' != $r['type'] ) { |
| 1942 | $comments_by_type = separate_comments($comments); |
| 1943 | if ( empty($comments_by_type[$r['type']]) ) |
| 1944 | return; |
| 1945 | $_comments = $comments_by_type[$r['type']]; |
| 1946 | } else { |
| 1947 | $_comments = $comments; |
| 1948 | } |
| 1949 | } |
| 1950 | } else { |
| 1951 | if ( empty($wp_query->comments) ) |
| 1952 | return; |
| 1953 | if ( 'all' != $r['type'] ) { |
| 1954 | if ( empty($wp_query->comments_by_type) ) |
| 1955 | $wp_query->comments_by_type = separate_comments($wp_query->comments); |
| 1956 | if ( empty($wp_query->comments_by_type[$r['type']]) ) |
| 1957 | return; |
| 1958 | $_comments = $wp_query->comments_by_type[$r['type']]; |