从前一个和下一个标记中删除‘Page-Numbers’类

时间:2019-10-14 作者:wp_noob

I\'m converting a template to WordPress theme and i need to change some css classes. The WordPress function paginate_links generates this markup:

    <ul>
        <li><a class="prev page-numbers" href="">Prev</a></li>
        <li><a class="page-numbers" href="">1</a></li>
        <li><a class="page-numbers" href="">2</a></li>
        <li><a class="page-numbers" href="">3</a></li>                        
        <li><a class="next page-numbers" href="">Next</a></li>
    </ul>

But I want to remove page-numbers class from the elements with prev or nextclass, to generate a result like this:

    <ul>
        <li><a class="prev" href="">Prev</a></li>
        <li><a class="page-numbers" href="">1</a></li>
        <li><a class="page-numbers" href="">2</a></li>
        <li><a class="page-numbers" href="">3</a></li>                        
        <li><a class="next" href="">Next</a></li>
    </ul>

I tried DOMXpath as cited here: Change class="page-numbers" in pagination

And also tried this: https://gist.github.com/pixeline/1dc662b756c553eb5efcb6ec4753375f

I don\'t know if it\'s possible to do what i want only with PHP. I\'m trying not to use jQuery to maintain the template as close of the original source.

Edit: CSS for the specific markup:

    .page { /* <nav> */
        margin: 3.2rem auto 3.2rem;
        text-align: center;
    }

    .page ul {
      display: inline-block;
      list-style: none;
      margin-left: 0;
      position: relative;
      padding: 0 6rem;
    }

    .page ul li {
      display: inline-block;
      margin: 0;
      padding: 0;
    }

    .page-numbers { 
      font-family: "Helvetica", sans-serif;
      font-weight: 700;
      font-size: 1.7rem;
      line-height: 3.2rem;
      display: inline-block;
      padding: 0.2rem 1.2rem;
      height: 3.6rem;
      margin: 0.2rem 0.2rem;
      color: #000000;
      transition: all, 0.3s, ease-in-out;
    }

    .page-numbers:hover {
      background: #d3d3d3;
      color: #000000;
    }

    .page .current,
    .page .current:hover {
      background-color: #000000;
      color: white;
    }

    .page .inactive,
    .page .inactive:hover { 
      opacity: 0.4;
      cursor: default;
    }

    .prev, 
    .next {
      display: block;
      background-repeat: no-repeat;
      background-size: 18px 9px;
      background-position: center;
      height: 3.6rem;
      width: 4.8rem;
      line-height: 2rem;
      padding: 0;
      margin: 0;
      opacity: 1;
      font: 0/0 a;
      text-shadow: none;
      color: transparent;
      transition: all, 0.2s, ease-in-out;
      position: absolute;
      top: 50%;
      -webkit-transform: translate3d(0, -50%, 0);
      transform: translate3d(0, -50%, 0);
    }

    .prev:hover,
    .next:hover {
      background-color: #d3d3d3;
      color: #000000;
    }

    .prev {
      background-image: url("../images/icons/arrow-left.svg");
      left: 0;
    }

    .next {
      background-image: url("../images/icons/arrow-right.svg");
      right: 0;
    }

    .prev.inactive,
    .next.inactive {
      opacity: 0.4;
      cursor: default;
    }

    .prev.inactive:hover,
    .next.inactive:hover {
      background-color: transparent;
    }
1 个回复
最合适的回答,由SO网友:Tom J Nowell 整理而成

您不必更改标记来改变上一个/下一个链接的样式:


.page-number {
    /* rules that apply to page numbers */
}

.prev.page-number {
    /* previous page link */
}
.next.page-number {
    /* rules that only apply to the next */
}
不需要删除链接上的类,可以使用基本的CSS专用性规则来完成

下面是一个代码笔,它演示了如何以不同的方式设置数字和上一个/下一个链接的样式:https://codepen.io/tomjn/pen/XWWKbbL

相关推荐

Adding pagination to my theme

我想为我的wordpress主题添加一个分页。然而,对我来说,这并不容易,因为我的主题是从插件“AT Posts Column”构建的,该插件在主页上显示最新的帖子。我想将分页添加到此插件:)。我尝试插入分页插件,并将代码粘贴到下面的文件的末尾。确实出现了分页,但当我进入下一页时,只有www.website上的链接发生了变化。com/page/2。请帮助:)。我的网站是http://consolezone.pl插件文件“在Posts列中”:<?php /** * Custom co