Hello everybody, 我需要有关自定义wordpress分页的帮助。
我想得到这个:
这就是我所做的:
在函数中。php,我添加了以下代码:
function wp_custom_pagination($args = [], $class = \'pagination\') {
if ($GLOBALS[\'wp_query\']->max_num_pages <= 1) return;
$args = wp_parse_args( $args, [
\'mid_size\' => 2,
\'prev_next\' => false,
\'prev_text\' => __(\'Older posts\', \'textdomain\'),
\'next_text\' => __(\'Newer posts\', \'textdomain\'),
\'screen_reader_text\' => __(\'Posts navigation\', \'textdomain\'),
]);
$links = paginate_links($args);
$next_link = get_previous_posts_link($args[\'next_text\']);
$prev_link = get_next_posts_link($args[\'prev_text\']);
$template = apply_filters( \'navigation_markup_template\', \'
<div class="col-auto">
<a href="" class="btn btn-outline-white text-dark">%3$s</a>
</div>
<div class="col-auto">
<nav class="navigation %1$s" role="navigation">
<h2 class="screen-reader-text">%2$s</h2>
<ul class="nav-links pagination mb-0 text-dark">
<li class="page-item">%4$s</li>
</ul>
</nav>
</div>
<div class="col-auto">
<a href="" class="btn btn-outline-white text-dark">%5$s</a>
</div>\', $args, $class);
echo sprintf($template, $class, $args[\'screen_reader_text\'], $prev_link, $links, $next_link);}
之后,我在家中添加了此代码。php
<?php wp_custom_pagination(); ?>
但是,结果真的不是我想要的!
以下是此wp\\u custom\\u分页所需的html结构代码:
<div class="row justify-content-between align-items-center">
<div class="col-auto">
<a href="#" class="btn btn-outline-white text-dark">Previous</a>
</div>
<div class="col-auto">
<nav>
<ul class="pagination mb-0 text-dark">
<li class="page-item active"><a class="page-link" href="#">1</a></li>
<li class="page-item"><a class="page-link" href="#">2</a></li>
<li class="page-item"><a class="page-link" href="#">3</a></li>
</ul>
</nav>
</div>
<div class="col-auto">
<a href="#" class="btn btn-outline-white text-dark">Next</a>
</div>
</div>
如果有人能帮助我,告诉我,告诉我我的错误,以及如何得到我想要的,请。
非常感谢
此时,我得到的结果是:
这是我的自定义分页页面的生成代码:
<div class="row justify-content-between align-items-center">
<div class="col-auto">
<a href="" class="btn btn-outline-white text-dark"></a>
<a href="http://192.168.1.87/wordpress/blog/page/2">Older posts</a>
</div>
<div class="col-auto">
<nav class="navigation pagination" role="navigation">
<h2 class="screen-reader-text">Posts navigation</h2>
<ul class="nav-links pagination mb-0 text-dark">
<li class="page-item">
<span aria-current="page" class="page-numbers current">1</span>
<a class="page-numbers" href="http://192.168.1.87/wordpress/blog/page/2">2</a>
</li>
</ul>
</nav>
</div>
<div class="col-auto">
<a href="" class="btn btn-outline-white text-dark"></a>
</div>
</div>
因此,如果你看看结果:
1-您将看到第一个链接(较旧的帖子=%3$s)需要使用好的css类!
2-您将看到;1、2、3“;链接需要在每个链接中”;“li”;不在一个内“;“li”;
最合适的回答,由SO网友:HK89 整理而成
在演示中根据需要定制分页设计。
以下函数替换您的函数:
function wp_custom_pagination($args = [], $class = \'pagination\') {
if ($GLOBALS[\'wp_query\']->max_num_pages <= 1) return;
$args = wp_parse_args( $args, [
\'mid_size\' => 2,
\'prev_next\' => false,
\'prev_text\' => __(\'Previous\', \'textdomain\'),
\'next_text\' => __(\'Next\', \'textdomain\'),
\'screen_reader_text\' => __(\'Posts navigation\', \'textdomain\'),
]);
$links = paginate_links($args);
$next_link = get_previous_posts_link($args[\'next_text\']);
$prev_link = get_next_posts_link($args[\'prev_text\']);
$check_prev = (!empty($prev_link))?$prev_link:\'Previous\';
$check_next = (!empty($next_link))?$next_link:\'Next\';
$template = apply_filters( \'navigation_markup_template\', \'
<div class="container"><div class= "row"><div style="display: flex;justify-content: space-around; align-items: center;" class="paginatin d-flex justify-content-between align-items-center"><div class="col-auto">
<button type="button" class="btn btn-outline-info" >%3$s</button>
</div>
<div class="col-auto">
<nav class="navigation %1$s" role="navigation">
<h2 class="screen-reader-text">%2$s</h2>
<ul class="pagination mb-0 text-dark">
<li class="page-item">%4$s</li>
</ul>
</nav>
</div>
<div class="col-auto">
<button type="button" class="btn btn-outline-info">%5$s</button>
</div></div></div><div>\', $args, $class);
echo sprintf($template, $class, $args[\'screen_reader_text\'], $check_next, $links, $check_prev);
}
在标题中添加一些Css:
function add_css_pagination(){
?>
<style type="text/css">
span.page-numbers.current {
background: #a8307c;
color: white;
}
button.btn a {
color: #f4f4f4;
text-decoration: none;
}
button.btn.btn-outline-info a {
color: darkslategrey;
font-weight: 600;
}
button.btn.btn-outline-info {
background: unset;
border: 1px solid turquoise;
color: darkslategrey;
font-weight: 600;
}
</style>
<?php
}
add_action(\'wp_head\',\'add_css_pagination\');
屏幕截图: