[wp-testers] Custom query

czArte de la Praga czarte at gmail.com
Sun Feb 27 14:07:20 UTC 2011


Hi to everyone, I`m just handling out the problem with paggination with
custom query. I`m using empty category to show posts from subcategories
situated under some sorting categories. For exampe: I have categories by
themes of posts eg. "Nature, Animals and Sunsets" and under this categories
are categories of the country names eg. "Italy, France, Germany". I need to
make cateogries that show the posts from all subcategories in all main
categories. So in main menu will be "Italy, France, Germany" and in there
will appear all posts form main categories "Nature, Animals and Sunsets" by
this quazi cats "Italy, France, Germany".

The problem is the paggination is not counting the page where I`m right now,
cause the category is emty, is there solution how to make custom query to be
on page which am I showing?

Not sure I`m handling custom query right way, but here is the code:

<?php

          $c = get_query_var( 'category_name'  );
            if (($c == 'francie' ) || ($c == 'germany' ) || ($c == 'italie'
) ) {
           $paged = get_query_var( 'page'  ) ;
           if (empty($paged)) : $paged = 1; endif;

           $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
           $prepag = substr($pageURL, -2);
           $prepag = str_replace('/', ' ', $prepag);

           $pag = ((int)$prepag );

           if ($pag > 0) { $page = ($pag - 1) * 12; } else { $page = 0; }



           if ($c == 'francie' ) {
           $catname = 'Francie';
           query_posts(array(
                'cat' => '5,12,17,21,101',
                'posts_per_page' => 12,
                'offset' => $page,
              ) );
              }

           if ($c == 'germany' ) {
            $catname = 'Germany';
           query_posts(array(
                'cat' => '7,14,90',
                'posts_per_page' => 12,
                'offset' => $page,
              ) );
              }

           if ($c == 'italie' ) {
            $catname = 'Itálie';
           query_posts(array(
                'cat' => '6,13,18,95',
                'posts_per_page' => 12,
                'offset' => $page,
              ) );
              }
?>

-- 
S pozdravem Vojtěch Parkán

Czarte Design
www.czarte.eu

Space Orange studio
www.spaceorange.eu


More information about the wp-testers mailing list