Display WordPress Page Navigation on Category Pages – A Very Easy Way

You should also take a look on New Hack for Displaying a Category Menu on WordPress

Cassio, a friend of mine, asked me to show in a very easy way, how to display page navigation on category pages. So, here we go…
Cassio, um amigo meu, me pediu para mostrar um jeito muito fácil de exibir navegação de página em páginas de categoria. Então, lá vamos nós…

Here is the code to use before the loop.
Aqui está o código a ser usado antes do loop.

 <?
	// choose a category
	$catnam = 'newposts';
	// get the total count of the posts for the choosen category
	$totpst = wt_get_category_count($catnam);
	// the page navigation variable, and the setting to start at page 1
	$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
	// the total of registers to show on each page
	$showp = 10;
	// the query, with all parameters
	query_posts("category_name=$catnam&showposts=$showp&paged=$paged");                                 			 	
?>            

Now, let’s run the loop.
Agora vamos executar o loop.

 <?

        if (have_posts()) :
	   while (have_posts()) : the_post();
              echo get_the_content();
           endwhile;         
	else:
              echo "There are no posts";
	endif;	                                			 	
?>            

Finally, we display the page navigation.
Finalmente, exibimos a páginação.

 <?
	// if the total count of posts is greater than the total of registers to show 
        // on each page(if you want, you can delete this if and end if)
        if($totpst  >= $showp):
	   next_posts_link('< Previous Posts'); 
	   echo " - ";
	   previous_posts_link('Recent Posts >'); 
	endif;	                                			 	
?>            

Hope you find it useful, Cassio🙂
Espero que você ache útil, Cassio🙂

,

  1. #1 by Geekyard on April 14, 2011 - 11:56 am

    My blog looks coll with this page navigation widget😉

    • #2 by Alvaro Neto on April 14, 2011 - 12:44 pm

      Hello Geekyard, thank you for your comment, good to know about it. Best regards.

  2. #3 by akismet-cce24891cb8071ee369e2b1bb7d1386a on June 26, 2011 - 8:56 pm

    Where do you put this code? And, just to make sure I understand what it does, as I understand it, it will keep the page navigation to the category that the post you’re looking at is in… right? As opposed to navigation based only on date of post.

    • #4 by Alvaro Neto on July 4, 2011 - 1:49 pm

      You can put it on a include, or on any page of your site. Best regards.

  1. Pass form values to WordPress query_posts(category name / category id) function to retrieve posts from a specific category « It works on WordPress

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: