在wordpress 4.1之前版本的默认主题中已内置了分页式导航,但并未集成到程序中。从4.1版本开始,官方将分页式导航函数正式集成到程序中,可以作为默认函数使用了。有了这个wordpress分页式导航函数,你就可以对其他第三方的分页代码和wordpress插件说再见了。
分页式导航调用函数:
- <?php
- the_posts_pagination( array(
- 'prev_text' =>上页,
- 'next_text' =>下页,
- 'before_page_number' => '<span class="meta-nav screen-reader-text">第 </span>',
- 'after_page_number' => '<span class="meta-nav screen-reader-text"> 页</span>',
- ) );
- ?>
注:此函数不支持WordPress 4.1之前的版本。
函数调用方法:将上面的分页式导航函数添加到wordpress主题的index、archive等模板文件的合适位置即可,如果再配以相应的样式,即可实现响应式转换,效果如下图所示:
具体的分页式导航样式代码:
- /** 等于或大于550px正常模式 **/
- @media screen and (min-width: 550px) {
- .pagination {
- float: rightright;
- }
- .pagination a, .pagination a:visited {
- float: left;
- background: #fff;
- margin: 0 5px 10px 0;
- padding: 8px 11px;
- line-height: 100%;
- border: 1px solid #ebebeb;
- border-radius: 2px;
- }
- .pagination .current, .pagination .dots {
- background: #fff;
- float: left;
- margin: 0 5px 0 0;
- padding: 8px 11px;
- line-height: 100%;
- border: 1px solid #ebebeb;
- border-radius: 2px;
- }
- .pagination span.pages {}
- .pagination span.current, .pagination a:hover {
- background: #0088cc;
- color: #fff;
- border: 1px solid #0088cc;
- }
- .screen-reader-text, .pages {
- display: none;
- }
- }
- /** 等于或小于550px用于移动设备 **/
- @media screen and (max-width: 550px) {
- .pagination {
- background: #fff;
- border: 1px solid #ebebeb;
- border-radius: 2px;
- }
- .pagination .nav-links {
- min-height: 30px;
- position: relative;
- text-align: center;
- }
- .pagination .current .screen-reader-text {
- position: static !important;
- }
- .screen-reader-text {
- height: 1px;
- overflow: hidden;
- position: absolute !important;
- }
- .page-numbers {
- display: none;
- line-height: 25px;
- padding: 5px;
- }
- .pagination .page-numbers.current {
- text-transform: uppercase;
- }
- .pagination .current {
- display: inline-block;
- }
- .pagination .prev,
- .pagination .next {
- background: #0088cc;
- color: #fff;
- display: inline-block;
- height: 29px;
- line-height: 29px;
- overflow: hidden;
- padding: 2px 8px;
- position: absolute;
- border: 1px solid #0088cc;
- }
- .pagination .next {
- border-radius: 0 2px 2px 0
- }
- .pagination .prev {
- border-radius: 2px 0 0 2px;
- }
- .pagination .prev a,
- .pagination .next a{
- color: #fff;
- line-height: 20px;
- padding: 0;
- display: inline-block;
- }
- .pagination .prev {
- left: 0;
- }
- .pagination .prev:before {
- left: -1px;
- }
- .pagination .next {
- rightright: 0;
- }
- .pagination .next:before {
- rightright: -1px;
- }
- }
注:本文介绍的wordpress技巧对于非响应式题,只需添加正常模式的样式代码即可(去掉媒体查询判断@media screen and )。
原文地址:http://zmingcx.com/wordpress-4-1-tabbed-navigation.html