Make WordPress Core

Ticket #30994: #30944_offsetreturn_wpgetarchives.diff

File #30944_offsetreturn_wpgetarchives.diff, 4.7 KB (added by jefflange, 10 years ago)

Patch for 30994

  • wp-includes/general-template.php

    diff --git wp-includes/general-template.php wp-includes/general-template.php
    index 6f0ff15..13b1f32 100644
    function get_archives_link($url, $text, $format = 'html', $before = '', $after = 
    13171317 *     @type bool|int   $echo            Whether to echo or return the links list. Default 1|true to echo.
    13181318 *     @type string     $order           Whether to use ascending or descending order. Accepts 'ASC', or 'DESC'.
    13191319 *                                       Default 'DESC'.
     1320 *     @type string|int $offset          Number of links to offset the query. Default empty.
    13201321 * }
    13211322 * @return string|null String when retrieving, null when displaying.
    13221323 */
    function wp_get_archives( $args = '' ) { 
    13281329                'format' => 'html', 'before' => '',
    13291330                'after' => '', 'show_post_count' => false,
    13301331                'echo' => 1, 'order' => 'DESC',
     1332                'offset' => '',
    13311333        );
    13321334
    13331335        $r = wp_parse_args( $args, $defaults );
    function wp_get_archives( $args = '' ) { 
    13461348                $order = 'DESC';
    13471349        }
    13481350
     1351        if ( ! empty( $r['offset'] ) ) {
     1352                $r['offset'] = absint( $r['offset'] );
     1353                $r['offset'] = ' OFFSET ' . $r['offset'];
     1354                if ( empty( $r['limit'] ) ) {
     1355                        $r['limit'] = ' LIMIT ' . PHP_INT_MAX;
     1356                }
     1357        }
     1358
    13491359        // this is what will separate dates on weekly archive links
    13501360        $archive_week_separator = '–';
    13511361
    function wp_get_archives( $args = '' ) { 
    13951405
    13961406        $limit = $r['limit'];
    13971407
     1408        $offset = $r['offset'];
     1409
    13981410        if ( 'monthly' == $r['type'] ) {
    1399                 $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date $order $limit";
     1411                $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date $order $limit $offset";
    14001412                $key = md5( $query );
    14011413                $key = "wp_get_archives:$key:$last_changed";
    14021414                if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
    function wp_get_archives( $args = '' ) { 
    14161428                        }
    14171429                }
    14181430        } elseif ( 'yearly' == $r['type'] ) {
    1419                 $query = "SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date) ORDER BY post_date $order $limit";
     1431                $query = "SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date) ORDER BY post_date $order $limit $offset";
    14201432                $key = md5( $query );
    14211433                $key = "wp_get_archives:$key:$last_changed";
    14221434                if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
    function wp_get_archives( $args = '' ) { 
    14351447                        }
    14361448                }
    14371449        } elseif ( 'daily' == $r['type'] ) {
    1438                 $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date $order $limit";
     1450                $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date $order $limit $offset";
    14391451                $key = md5( $query );
    14401452                $key = "wp_get_archives:$key:$last_changed";
    14411453                if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
    function wp_get_archives( $args = '' ) { 
    14561468                }
    14571469        } elseif ( 'weekly' == $r['type'] ) {
    14581470                $week = _wp_mysql_week( '`post_date`' );
    1459                 $query = "SELECT DISTINCT $week AS `week`, YEAR( `post_date` ) AS `yr`, DATE_FORMAT( `post_date`, '%Y-%m-%d' ) AS `yyyymmdd`, count( `ID` ) AS `posts` FROM `$wpdb->posts` $join $where GROUP BY $week, YEAR( `post_date` ) ORDER BY `post_date` $order $limit";
     1471                $query = "SELECT DISTINCT $week AS `week`, YEAR( `post_date` ) AS `yr`, DATE_FORMAT( `post_date`, '%Y-%m-%d' ) AS `yyyymmdd`, count( `ID` ) AS `posts` FROM `$wpdb->posts` $join $where GROUP BY $week, YEAR( `post_date` ) ORDER BY `post_date` $order $limit $offset";
    14601472                $key = md5( $query );
    14611473                $key = "wp_get_archives:$key:$last_changed";
    14621474                if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
    function wp_get_archives( $args = '' ) { 
    14841496                }
    14851497        } elseif ( ( 'postbypost' == $r['type'] ) || ('alpha' == $r['type'] ) ) {
    14861498                $orderby = ( 'alpha' == $r['type'] ) ? 'post_title ASC ' : 'post_date DESC ';
    1487                 $query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit";
     1499                $query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit $offset";
    14881500                $key = md5( $query );
    14891501                $key = "wp_get_archives:$key:$last_changed";
    14901502                if ( ! $results = wp_cache_get( $key, 'posts' ) ) {