Title: Advanced Categorization
Last modified: August 19, 2016

---

# Advanced Categorization

 *  [jcaren](https://wordpress.org/support/users/jcaren/)
 * (@jcaren)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/advanced-categorization/)
 * I am creating a new magazine style site for a client with an interesting need….
   I am having a hard time figuring out the best way to achieve this…here is what
   they need…
 * They have lets say 4 regional categories…
 * Area 1
    Area 2 Area 3 Area 4
 * Then they have let’s say 4 main categories with subcategories…
 * Home Furnishing
    chairs sinks lights
 * Outdoor Life
    benches parks chairs
 * Pools
    toys equipment
 * Storage
    garage basement attic
 * Now, EACH of those categories/subcategories will be listed under EACH of the 
   regions…..
 * If a reader clicks on a region first…then a category….ONLY articles from that
   region should be returned…..(excluding all other regions)
 * If a reader clicks on a category first – it should return ALL articles in that
   category from all the regions….but then they should have the ability to then 
   narrow down to a region if they choose to so they can only view articles from
   that region….
 * Confused yet?!?!?
 * I know its a long shot….but has anyone done anything similar that can offer some
   advice….I am still researching options, but thought I would throw it out there
   just in case!
 * I am trying to work with taxonomies but so far have not achieved what I need….
   any help is greatly appreciated!!!!
 * Thanks so much!!!
 * Jill

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [cemery](https://wordpress.org/support/users/cemery/)
 * (@cemery)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/advanced-categorization/#post-1763503)
 * I’m have a similar issue, Jill. I’m trying to have certain category pages such
   as [http://www.mysite.com/category/something](http://www.mysite.com/category/something)
   display several blocks of post teasers from that category based on co-categories.
 * So, for instance, it would look like:
 * Main category for page: Vermont
    Loop 1: Activities (in Vermont) Loop 2: National
   Parks (in Vermont) Loop 3: Stores (in Vermont)
 * I’d like to do things to each of these loops, such as limiting the post number
   and having a “featured” first post with a post thumbnail displayed.
 * The confusing part, for me, is preserving the parameters created by the category
   URL while modifying the multiple loops on the page to create the filtered blocks.
 * Using query_post to filter each loop seemed like a good idea, but the Function
   reference entry says it shouldn’t be used for multiple loops. Also, it overrides
   the parameters from the category URL, unless you use:
 * `global $query_string;`
 * and then recall it as such:
 * `query_posts($query_string . "&order=ASC");`
 * Perhaps it’s a matter of putting conditional category logic inside the standard
   loop, as they show on [The Loop page](http://codex.wordpress.org/The_Loop) in
   the documentation
 *     ```
       <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
   
        <?php if ( in_category('3') ) { ?>
   
        <?php } else { ?>
   
        <?php } ?>
       ```
   
 * But this doesn’t solve my questions about limiting the number of posts shown 
   or perhaps excluding certain post types from showing up in the loop.
 * If I figured it out I’ll let you know.
 *  [cemery](https://wordpress.org/support/users/cemery/)
 * (@cemery)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/advanced-categorization/#post-1763506)
 * I just cam across this post which might offer some clues:
 * [http://wordpress.org/support/topic/pass-variable-into-category_and-array?replies=4#post-897517](http://wordpress.org/support/topic/pass-variable-into-category_and-array?replies=4#post-897517)
 * Seems he combined the URL-generated ‘cat’ parameter with another category ID 
   in an array, then passed it as a variable into category_and. I’m guessing one
   needs to further modify the query_post arguments to change things like post count.
 * This still doesn’t address the warning not to use query_posts in multiple loops–
   but maybe I’m misinterpreting what “multiple loops means…?
 * Here’s his code:
 *     ```
       <?php
   
       $cid = get_query_var('cat');
       $myarray = array($cid,21);
       query_posts(array('category__and'=>$myarray)); ?>
       <?php while (have_posts()) : the_post(); ?>
   
       <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>
       <p><?php the_excerpt('Read more »'); ?></p>
   
       <?php endwhile; ?>
       ```
   
 *  Thread Starter [jcaren](https://wordpress.org/support/users/jcaren/)
 * (@jcaren)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/advanced-categorization/#post-1763507)
 * Actually I think I got it to work how I need it with this plugin
 * [http://wordpress.org/extend/plugins/custom-taxonomies-menu-widget/](http://wordpress.org/extend/plugins/custom-taxonomies-menu-widget/)
 * It allows the reader to pick a category and then when they click on a “tag” they
   can pull only the articles for that tag…..from within that specified category….
 * Then they can choice a “tag” and then narrow down by category….so it works both
   ways as I needed it to…..
 * Still playing but so far it works perfectly!!!!
 *  [cemery](https://wordpress.org/support/users/cemery/)
 * (@cemery)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/advanced-categorization/#post-1763521)
 * Awesome! I think I found my answer, too. I modified the code I posted above with
   a get_posts loop and got this:
 *     ```
       <?php
       $cid = get_query_var('cat');
       global $post;
       $myposts = get_posts('cat=-22,-21,' . $cid . '&numberposts=5');
       foreach($myposts as $post) :
         setup_postdata($post);
       ?>
          <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
       <?php endforeach; ?>
       ```
   
 * This grabs the category parameter from the URL and passes it as the variable 
   $cid to the get_posts function. By concatenating that variable with other category
   ids to remove the things I don’t want to see in the loop (i.e., “-22,-21”) I 
   can drill down to what I want to display.
 * Using the get_posts function also allows me to add other filters, such as post
   count and offset.
 * The only thing I’d like to change is to be able to filter the URL category id
   based on “and” logic – as in category_and – instead of subtracting out categories.
   Seems more elegant and manageable.
 * Does anybody know if you can pass category_and as an argument to get_posts with
   additional filters included such as numberposts, offset, etc? If so, do you have
   an example…?

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Advanced Categorization’ is closed to new replies.

## Tags

 * [categories](https://wordpress.org/support/topic-tag/categories/)
 * [taxonomy](https://wordpress.org/support/topic-tag/taxonomy/)

 * 4 replies
 * 2 participants
 * Last reply from: [cemery](https://wordpress.org/support/users/cemery/)
 * Last activity: [15 years, 6 months ago](https://wordpress.org/support/topic/advanced-categorization/#post-1763521)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
