2

I am using paginate_links on my custom page query.

What I have already works sweet and this is the code I have so far...

<?php
    global $wp_query;

    $big = 999999999; // need an unlikely integer

    echo paginate_links( array(
        'base'      => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
        'format'    => '?paged=%#%',
        'current'   => max( 1, get_query_var('paged') ),
        'total'     => $wp_query->max_num_pages,
        'prev_text' => __('&#8592; Previous'),
        'next_text' => __('Next &#8594;')
    ));
?>

Though I really need to be it a bit more different, but can't find any documentation on how to bend the rules with it.

Question 1
I need the prev_text and next_text to be translatable. I have been adding my theme text domain for localization through-out my theme. And on generic text strings, I have been using this <?php _e('Latest Dowloads','mythemetextdomain'); ?>. How can I add my theme text domain into the prev_text and next_text string.

Question 2
How can I add <span class="bracket">[</span> and <span class="bracket">]</span> between each of my paginated page numbers?

Please see image below of what my current pagination is looking like.

enter image description here

Now see image below of what I'm trying to achieve by using spans and brackets.

enter image description here

Can any help me modify my paginate query above to get these 2 things to work? Or is it not possible?

Thanks

  • If you really want brackets cross-browser, why not consider using a CSS background to archieve that effect, you won't need to mess with filters or code, simply apply an appropriately made image via CSS(it might seem odd, but it would be a simple solution). – t31os Dec 21 '11 at 22:45
  • There is a filter you could use for string replacement, but following on from what i said above, this would actually be really easy using CSS to apply background images to those items(and works around needing to do any filtering). If you are determined to add brackets literally though, let me know and i'll provide a real answer.. ;) – t31os Dec 21 '11 at 22:46
2

The function paginate_links() can return "plain", "list" and "array" (http://codex.wordpress.org/Function_Reference/paginate_links). Just define the type as array then you'll be to display it as you want:

<?php
    global $wp_query;

    $big = 999999999; // need an unlikely integer

    $paginate_links = paginate_links( array(
        'base'      => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
        'format'    => '?paged=%#%',
        'current'   => max( 1, get_query_var('paged') ),
        'total'     => $wp_query->max_num_pages,
        'prev_text' => __('&#8592; Previous'),
        'next_text' => __('Next &#8594;'),
        'type'      => 'array'
    ));

    foreach ( $paginate_links as $pgl ) {
        echo "[ $pgl ]";
    }
?>
1

For the brackets, I'd try to do:

.pagenumber:before { content:'['; }
.pagenumber:after { content:']'; }

And you can also use margins, paddings, positioning, etc. to get it exactly how you want it.

  • Yeah this is what I thought about doing but content: is not IE7 compatible, suppose I could live with that. Also pagination I don't think is not outputting li's. Thanks – Joshc Dec 21 '11 at 16:06
  • This is what is was talking about but use the page_number class instead. – Joseph Leedy Dec 21 '11 at 16:15
0

Question 1: Use __ (double underscore) instead of _e.

Question 2: There may be a filter or hook available to do this but you can also use CSS to generate content for the page_number class.

  • Thanks for question 1 so, I wrote it like this... 'prev_text' => __('&#8592; Previous','mythemetextdomain'), 'next_text' => __('Next &#8594;','mythemetextdomain') – Joshc Dec 21 '11 at 14:28
  • Suppose I could get clever with css, but would rather out markup if you know what I mean. Thanks – Joshc Dec 21 '11 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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