When a post is split on more pages TwentyTen theme use the native function wp_link_pages
to display a navigation page bar at the end of post.
I am trying to style those elements for my theme, but unfortunately it seems that the current page number cannot be styled.
I imagine that I should override the wp_link_pages
function but I am still learning the basic of WP programming.
Can you help me identifing the steps to follow to solve this problem?
Unfortunately, there is no way to do this just with native functions: WP is ⦠request agnostic and produces always links to the current page (nav manus, list pages â¦).
Also, you cannot use a filter, because
wp_link_pages()
has no appropriate filter.In my themes, I use an own function, based on this code. It is probably too long to post it here, so I put it as a plugin on GitHub: Logical Page Links.
You may use the plugin as is or copy the code into your theme.
The resulting markup will look like this:
The
<b>
marks the current page, you can style it via:More features are listed in the readme of the plugin.
Update
I misunderstood the question. I thought you needed such a function for archives. Sorry.
Here is a rewritten version of
wp_link_pages()
as a plugin. I guess youâll put it into your theme.A simple way I’m using now, is to use ‘link_before’ and ‘link_after’ as part of the wp_link_pages args. You can then wrap each number, including the active one, in a tag, then style appropriately.
I agree with seb; the way to do it is to use link_before and link_after. To expand on that, use, for example,
'link_before' => '<span class="page-link-number">', 'link_after' => '</span>'
Then you will have output:
where we are currently on page two.
THEN you can style on whether the class “page-link-number” is the child of a link or not.
First, you need to provide a CSS class to target, which you can do using the arguments of
wp_link_pages()
itself:Now, just style the
.link-pages
class. Here’s what I use:Style according to your needs, of course.
@toscho thanks for the post, it helped a lot! I went a little further and added list item tags to both outputs, so I could style it with more ease.
I’m pasting this hack to your code as it could help someone.
Camilo
It is possible to mark the current page using a WP filter. The filter
wp_link_pages_link
used inwp_link_pages()
receives the link item, which is a single number for the current page, and an anchor for other pages. So we can check if the item is a number and wrap it in a span:Of course, assuming you’re not already filtering the links in a way that the current page is no longer a single number. You can then stylize it using the
current
class.