your best option is to create 3 new categories called region, country and city and manually add the posts to them.. then show as dropdown select, organic tabs, seperate pages or whatever..
Thanks shadez.
That’s exactly what I did. Unfortunately it doesn’t allow for any different style of display on the new pages itself.
I have posts about London, England and Athens, Greece and Chicago, Illinois for example. I would of course have to connect them to the category “city,” “region” and “country” so the only thing that happens is all the posts show up on all the pages the exact same way. Each page basically looks the same.
I want a way to have all the posts GROUPED on each page. The first posts listed when on the region page will all be from the first region in alphabetical order (let’s just say Central America because I don’t feel like thinking ;). Then you’d see all the posts from North America together, and then the next. If you click on country, I want all the posts from Greece grouped together and all the posts from Italy grouped together. City is the only page that will display like a normal page, populated in alphabetical order by post title.
I have no idea if this is possible. I am hoping someone can get me started if so or offer me a similar solution. Thanks.
ok so you have a parent category called ‘region’, and many child categories of it say ‘north america’, ‘south america’, etc. and basically you wish to display all child categories and their respective posts. right?
heres a great code from alchymyth which i have bookmarked: http://pastebin.com/jwThuY5R
this code finds the category of current post. so remove that part and give ‘regions’ category ID directly into get_categories() funtion and its good to roll.
same goes for countries. and city is direct category page fetching.
also check: http://codex.ww.wp.xz.cn/Class_Reference/WP_Query#Parameters
and if you are looking for faceted search then thats quite complicated. so try some plugins first. but again, some major WP default search engine changes were made in v3.7 so check stability of plugins before going live.
This is really helpful, shadez. Thanks.
I am afraid I am new at working with this sort of code however and am having some difficulty figuring out what to edit.
<?php
wp_reset_query();
if(is_single()) :
$catts = '';
$cats = get_the_category($post->ID); // get all post's categories
if($cats) : foreach($cats as $cat) :
$categories = get_categories( 'child_of=' . $cat->term_id ); // get child of category
if($categories) : foreach($categories as $category) :
$catts[] = $category->term_id; // collect child category id in array
endforeach; endif;
endforeach; endif;
if($catts) :
$catts = array_unique($catts); // remove double category id
sort($catts); // sort asc
$kitten = implode(',',$catts); // turn into string for the query
query_posts('cat=' . $kitten . '&posts_per_page=-1' );
if(have_posts()) : while(have_posts()) : the_post();
the_title(); echo '<br />'; // put here what you want to show
endwhile; endif; // end of the loop
endif;
endif; // end if(is_single())
?>
Here’s the code you gave me. All the areas marked “kitten” I am assuming are for a category named “Kitten” and I would have to change this to my category name? Also, if I am trying to use this code for the two pages, do I list both my categories here in the same string? (region and country)?
Do I remove this line of code? : $cats = get_the_category($post->ID); // get all post’s categories
Do I add my categories here? : $categories = get_categories( ‘child_of=’ after the equals sign? Add them both separated by a comma?
I know I’m asking a lot from you but it seems you know exactly what I am trying to accomplish and I appreciate your help. I am just having some trouble working with this code. Thanks!