首页 > 解决方案 > 如何在functions.php中添加分页WordPress

问题描述

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

函数.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;
}

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

标签: phpwordpressfunctionblogs

解决方案


推荐阅读