我正在尝试在 HTML 类中替换和添加一些值...我在某种程度上成功地解决了这个问题,但现在我需要帮助。这是我的功能代码
function wpse247219_custom_pagination() {
global $the_query;
$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('page') ),
'total' => $the_query->max_num_pages,
'prev_next' => false,
'type' => 'array',
'prev_next' => true,
'prev_text' => __( 'Previous', 'text-domain' ),
'next_text' => __( 'Next page', 'text-domain'),
) );
$output = '';
if ( is_array( $pages ) ) {
$paged = ( get_query_var('paged') == 0 ) ? 1 : get_query_var( 'paged' );
$output .= '<ul class="pagination-list">';
foreach ( $pages as $page ) {
$output .= "<li>$page</li>";
}
$output .= '</ul>';
$dom = new \DOMDocument();
$dom->loadHTML( mb_convert_encoding( $output, 'HTML-ENTITIES', 'UTF-8' ) );
$xpath = new \DOMXpath( $dom );
$page_numbers = $xpath->query( "//*[contains(concat(' ', normalize-space(@class), ' '), ' page-numbers ')]" );
foreach ( $page_numbers as $page_numbers_item ) {
$page_numbers_item_classes = explode( ' ', $page_numbers_item->attributes->item(0)->value );
if ( in_array( 'current', $page_numbers_item_classes ) ) {
$list_item_attr_class = $dom->createAttribute( 'class' );
$list_item_attr_class->value = 'mynewclass';
$page_numbers_item->parentNode->appendChild( $list_item_attr_class );
}
现在我还想替换<span class="page-numbers current">
to的类<span class="pagination-link is-current ">
,使其看起来像这样
我还试图<li></li>
从下一页和上一页按钮中删除标签。任何类型的帮助将不胜感激
HUX布斯
小怪兽爱吃肉