php - 如何在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;
}
一切正常,但我想添加分页按钮
解决方案
推荐阅读
- javascript - 我的代码和其他代码有什么区别?
- python-3.x - 加载泡菜 NotFittedError:TfidfVectorizer - 未安装词汇
- c - 在 C 中动态插入结构数组。退出,分段错误
- opencv - Opencv 的 Opencl 代码中的 WTV 用于图像调整大小
- html - 使用 Apache,如何在使用反向代理从另一台服务器返回的页面上解释 SSI?
- node.js - 应用正则表达式时避免创建空格
- ionic-framework - 如何在 Ionic App 中集成 TLS 套接字?
- c - 如何将数组中的数字更改为符号
- reactjs - React 映射中的键问题
- wordpress - Mac Apache / PHP 不会仅针对一个站点和分段错误启动会话