Make WordPress Core

Ticket #37312: 37312.diff

File 37312.diff, 1.4 KB (added by welcher, 7 years ago)

Changing to foreach

  • src/wp-includes/widgets/class-wp-widget-recent-posts.php

    diff --git src/wp-includes/widgets/class-wp-widget-recent-posts.php src/wp-includes/widgets/class-wp-widget-recent-posts.php
    index c8d19055b4..19ad5371af 100644
    class WP_Widget_Recent_Posts extends WP_Widget { 
    8080                        echo $args['before_title'] . $title . $args['after_title'];
    8181                } ?>
    8282                <ul>
    83                 <?php while ( $r->have_posts() ) : $r->the_post(); ?>
     83                        <?php
     84                        foreach ( $r->posts as $recent_post ) :
     85                                $post_title = get_the_title( $recent_post->ID );
     86                                $title      = ( ! empty( $post_title ) ) ? $post_title : __( '(no title)' );
     87                                ?>
    8488                        <li>
    85                                 <a href="<?php the_permalink(); ?>"><?php get_the_title() ? the_title() : _e( '(no title)' ); ?></a>
    86                         <?php if ( $show_date ) : ?>
    87                                 <span class="post-date"><?php echo get_the_date(); ?></span>
    88                         <?php endif; ?>
     89                                <a href="<?php get_the_permalink( $recent_post->ID ); ?>"><?php echo $title ; ?></a>
     90                                <?php if ( $show_date ) : ?>
     91                                        <span class="post-date"><?php echo get_the_date( '', $recent_post->ID ); ?></span>
     92                                <?php endif; ?>
    8993                        </li>
    90                 <?php endwhile; ?>
     94                        <?php endforeach;?>
    9195                </ul>
    92                 <?php echo $args['after_widget']; ?>
    93                 <?php
    94                 // Reset the global $the_post as this query will have stomped on it
    95                 wp_reset_postdata();
    96 
     96                <?php echo $args['after_widget'];
    9797                endif;
    9898        }
    9999