Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to make something more meaningful out of the wp_link_pages() result:

$paged_page_nav = wp_link_pages( array( 'echo' => false ) );
// Now let's wrap the nav inside <li>-elements
$paged_page_nav = str_replace( '<a', '<li class="'.$classes.'"><a', $paged_page_nav );
$paged_page_nav = str_replace( '/a>', '/a></li>', $paged_page_nav );

// here I'd need to wrap the currently displayed page element

echo '<ul>'.$pages_page_nav.'</ul>';

Currently my link pages (numbered nav/pagination) displays like this:

<!-- assuming we display page(d) 2/5 -->
<ul>
    <li><a href="...">1</a></li>
    2 <!-- This is the currently displayed paged, wrapped in nothing -->
    <li><a href="...">3</a></li>
    <li><a href="...">4</a></li>
    <li><a href="...">5</a></li>
</ul>
share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

I wouldn’t use WordPress’ internal function.
We had a very similar question recently: How to style current page number (wp_link_pages)? I wrote a small but flexible function to replace wp_link_pages(). It is probably easier to extend this than hacking around the return value of the native function.

share|improve this answer
    
thanks for the link, I couldn't find anything useable myself. Using the 'wp_link_pages_args' filter is a pretty smart move. Added the "if you build something better, make native filters available"-thought to my tool box. Thanks again, learned something today. :) –  kaiser May 16 '11 at 23:17
    
@kaiser I just tagged the other post with wp-link-pages. Now we have two post posts for this tag. :) –  toscho May 17 '11 at 10:23
add comment

you could try and use the 'link_before' and 'link_after' parameter to get a handle for some str_replace; in the example, i used a <span>:

$paged_page_nav = wp_link_pages( 
  array( 
    'before' =>'', 
    'after' => '', 
    'link_before' => '<span>', 
    'link_after' => '</span>', 
    'echo' => false 
  ) 
); 
// Now let's wrap the nav inside <li>-elements 
  $paged_page_nav = str_replace( '<a', '<li class="'.$classes.'"><a', $paged_page_nav ); 
  $paged_page_nav = str_replace( '</span></a>', '</a></li>', $paged_page_nav );
  $paged_page_nav = str_replace( '"><span>', '">', $paged_page_nav ); 
// here I'd need to wrap the currently displayed page element, which could even get a different class      
  $paged_page_nav = str_replace( '<span>', '<li class="'.$classes.'">', $paged_page_nav ); 
  $paged_page_nav = str_replace( '</span>', '</li>', $paged_page_nav ); 
echo '<ul>'.$paged_page_nav.'</ul>';
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.