• Is there any way possible to add styles to the current/non-link pages numbers when using the wp_link_pages code?

    I used the code below to display the page numbers of a post and you are able to target the links (.PostPages a {} ) using this, but the current page doesn’t seem to have any way to target and apply some CSS so it doesn’t look so goofy.

    <?php wp_link_pages('before=<div class="PostPages">&after=</div>&pagelink=%'); ?

Viewing 1 replies (of 1 total)
  • Thread Starter alanchrishughes

    (@alanchrishughes)

    Nevermind, I actually found this hack to fix it if anybody else is looking to do the same. Just use custom_wp_link_pages instead of wp_link_pages

    http://wpdojo.net/tag/wp_link_pages/

    function custom_wp_link_pages( $args = '' ) {
    	$defaults = array(
    		'before' => '<p id="post-pagination">' . __( 'Pages:' ),
    		'after' => '</p>',
    		'text_before' => '',
    		'text_after' => '',
    		'next_or_number' => 'number',
    		'nextpagelink' => __( 'Next page' ),
    		'previouspagelink' => __( 'Previous page' ),
    		'pagelink' => '%',
    		'echo' => 1
    	);
    
    	$r = wp_parse_args( $args, $defaults );
    	$r = apply_filters( 'wp_link_pages_args', $r );
    	extract( $r, EXTR_SKIP );
    
    	global $page, $numpages, $multipage, $more, $pagenow;
    
    	$output = '';
    	if ( $multipage ) {
    		if ( 'number' == $next_or_number ) {
    			$output .= $before;
    			for ( $i = 1; $i < ( $numpages + 1 ); $i = $i + 1 ) {
    				$j = str_replace( '%', $i, $pagelink );
    				$output .= ' ';
    				if ( $i != $page || ( ( ! $more ) && ( $page == 1 ) ) )
    					$output .= _wp_link_page( $i );
    				else
    					$output .= '<span class="current-post-page">';
    
    				$output .= $text_before . $j . $text_after;
    				if ( $i != $page || ( ( ! $more ) && ( $page == 1 ) ) )
    					$output .= '</a>';
    				else
    					$output .= '</span>';
    			}
    			$output .= $after;
    		} else {
    			if ( $more ) {
    				$output .= $before;
    				$i = $page - 1;
    				if ( $i && $more ) {
    					$output .= _wp_link_page( $i );
    					$output .= $text_before . $previouspagelink . $text_after . '</a>';
    				}
    				$i = $page + 1;
    				if ( $i <= $numpages && $more ) {
    					$output .= _wp_link_page( $i );
    					$output .= $text_before . $nextpagelink . $text_after . '</a>';
    				}
    				$output .= $after;
    			}
    		}
    	}
    
    	if ( $echo )
    		echo $output;
    
    	return $output;
    }
Viewing 1 replies (of 1 total)

The topic ‘wp_link_pages CSS for Current Page?’ is closed to new replies.