如何在functions.php中添加分页WordPress

时间:2019-06-27 12:59:56

标签: php wordpress function blogs

该博客有100多个帖子页面。我想在WordPress functions.php中添加分页,但是如何在其中添加代码

functions.php

/**
 * Shortcode News
 */
add_shortcode( 'news', 'new_bubble' );

function new_bubble(){
    $args = array(
        'post_type'         => 'post',
        'post_status'       => 'publish',
        'posts_per_page'    => '20',
        'paged'                 => $paged
    );
    $query = new WP_Query( $args );
    if( $query->have_posts() ){
        $string .= '<div class="row">';
        while( $query->have_posts() ){
            $query->the_post();
            $string .= '<div class="col-md-4">';
            $string .= '<div class="card">';
            $string .= '<a href="' . get_the_permalink() . '">';
            $string .= '<div class="card-img" style="background-image: url(' . get_the_post_thumbnail_url() . ');">';
            $string .= '</div>';
            $string .= '</a>';
            $string .= '<div class="card-body">';
            $string .= '<p class="post-date">' . get_the_date( 'j F Y' ) . '</p>';
            $string .= '<p class="post-title">';
            $string .= '<a href="' . get_the_permalink() . '">';
            $string .= '' . get_the_title() . '';
            $string .= '</a>';
            $string .= '</p>';
            $string .= '<div class="post-footer">';
            $string .= '<div class="author">';
            $string .= ''. get_avatar( get_the_author_email(), '50' ) . '';
            $string .= '<div class="author-meta">';
            $string .= '<h5 class="author-post-name">By ' . get_the_author() . '</h5>';
            $string .= '</div>';
            $string .= '</div>';
            $string .= '</div>';
            $string .= '</div>';
            $string .= '</div>';
            $string .= '</div>';
        }
        $string .= '</div>';
    }
    wp_reset_postdata();
    return $string;
}

一切正常,但我想添加分页按钮

0 个答案:

没有答案