2 回答
TA贡献1841条经验 获得超3个赞
将以下内容添加到文件底部:search.php
<?php
if ( $GLOBALS['wp_query']->max_num_pages <= 1 ) {
return;
}
$args = wp_parse_args(
$args,
array(
'mid_size' => 2,
'prev_next' => true,
'prev_text' => __( '«' ),
'next_text' => __( '»' ),
'screen_reader_text' => __( 'Posts navigation' ),
'type' => 'array',
'current' => max( 1, get_query_var( 'paged' ) ),
)
);
$links = paginate_links( $args ); ?>
<nav>
<ul class="pagination">
<?php
foreach ( $links as $key => $link ) {
?>
<li class="page-item <?php echo strpos( $link, 'current' ) ? 'active' : ''; ?>">
<?php echo str_replace( 'page-numbers', 'page-link', $link ); ?>
</li>
<?php } ?>
</ul>
</nav>
TA贡献1834条经验 获得超8个赞
我也在寻找相同的解决方案来将其与引导分页链接一起使用,
下面的代码在我的主题中100%工作。
function bittersweet_pagination() {
global $wp_query;
if ( $wp_query->max_num_pages <= 1 ) return;
$big = 999999999; // need an unlikely integer
$pages = paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages,
'type' => 'array',
) );
if( is_array( $pages ) ) {
$paged = ( get_query_var('paged') == 0 ) ? 1 : get_query_var('paged');
echo '<div class="pagination-wrap"><ul class="pagination">';
foreach ( $pages as $page ) {
echo "<li>$page</li>";
}
echo '</ul></div>';
}
}
使用函数调用索引.php例如;或任何其他文件。我还覆盖了一些引导样式,它可能会帮助你。
.pagination-wrap {
clear: both;
display: block;
overflow: hidden;
text-align: center;
}
.pagination-wrap .pagination {
margin-bottom: 0;
margin-top: 0;
}
.pagination-wrap .pagination > li:first-child > a,
.pagination-wrap .pagination > li:first-child > span {
border-bottom-left-radius: 0px;
border-top-left-radius: 0px;
}
.pagination-wrap .pagination > li:last-child > a,
.pagination-wrap .pagination > li:last-child > span {
border-bottom-right-radius: 0px;
border-top-right-radius: 0px;
}
.pagination-wrap .pagination > li > a,
.pagination-wrap .pagination > li > span {
background-color: #4FBEBA;
border: 1px solid #1BA5A0;
padding: 10px 15px;
font-weight: bold;
color: #FFFFFF;
}
.pagination-wrap .pagination > li > a:hover,
.pagination-wrap .pagination > li > span:hover,
.pagination-wrap .pagination > li > a:focus,
.pagination-wrap .pagination > li > span:focus {
background-color: #1BA5A0;
border-color: #189690;
}
.pagination-wrap .pagination .current {
background-color: #1BA5A0;
border-color: #189690;
}
.pagination-wrap .pagination .current:hover,
.pagination-wrap .pagination .current span:hover {
background-color: #189690;
border-color: #148781;
}
祝你好运,兄弟。
- 2 回答
- 0 关注
- 110 浏览
添加回答
举报