I have a page that displays a list of all tags of my blog. Iuse this code which works fine:
<?php
$poststocount=get_tags($args);
echo '<h2>Alphabetic Index of All '</h2>';
?>
<?php
$taxonomy = 'post_tag';
$tax_terms = get_terms($taxonomy);
?>
<ul>
<?php
foreach ($tax_terms as $tax_term) {
echo '<li>' . '<a href="' . esc_attr(get_term_link($tax_term, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $tax_term->name ) . '" ' . '>' . $tax_term->name.'</a></li>';
}
?>
</ul>
Question: how can I paginate this lidt (say 40 per page). What would the code to accompish that, preferably with an option to “see all tags”.
Thanks.
you could paginate your page by simply adding
/page/n
to the end of the URL, wheren
is the desired page number. creating your next/prev links will be a manual affair though. the page number will then be accessible viaget_query_var('paged')
. then use thenumber
argument forget_terms
to select 40 at a time, use theoffset
argument, which will be your page number -1 * number per page, to select the current “page” of terms:as for viewing all, maybe append a GET var to the URL,
?showall=true
, then checkisset( $_GET['showall'] )
and change the number to fetch accordingly.EDIT
here’s a quick template I made to show an example. I tested it on a page on a test install with pretty permalinks, the page was ‘about’, so the pagination links were:
if your permalinks are different, you’ll have to edit the pagination section to reflect your setup.
This question asked long time ago. Here is the easiest solution I found.
Then use paginate_links() function after loop.