March 25, 201016 yr Alright guru's! I need some help. I have a two tiered navigation structure on a site for work; one is the main navigation, and when the user selects that, they see ALL posts within that and all sub categories, now that is working fine. What I need to do, is in a sidebar, to list all sub-categories of the selected category. At the moment I have: <?php wp_list_categories('title_li=&child_of=3'); ?> But I need to make 'child_of' the current category in the URL - does that makes sense? Ta Tel
March 25, 201016 yr Have you looked at the codex? http://codex.wordpress.org/Function_Reference/get_the_category Not sure how to integrate it to be honest but it should be fairly straightforward to extract the category and put it in your wp_list_categories
March 25, 201016 yr Author Hi Jay, Yes I have had a look - I have the category stored in a variable, but how do I input that as an argument? I currently have: <?php wp_list_categories('title_li=&child_of=$parent'); ?> But that isn't working Help
March 25, 201016 yr Very close my friend. Just need to change the single quotes to double quotes or concatenate the parent to the string first method <?php wp_list_categories("title_li=&child_of=$parent"); ?> second method <?php wp_list_categories('title_li=&child_of='.$parent); ?> Personally I would go for the second method. I'm not a fan of putting variables directly into strings, but either will work
March 25, 201016 yr Author Argh - bugger! Sorry Jay, one more question mate... I am using this code to get the parent category: <?php $category = get_the_category(); $cats = $category[0]->term_id; echo $cats; ?> BUT the problem is, it is pulling the categories into the array in alphabetic order, rather than numerical order... or just the highest ranking (or parent) page - any idea how I would tell the array to do it in number order instead of alpha? Cheers
March 25, 201016 yr Can you put the following after your first line and paste the output here so that I know what the array looks like echo '<pre>'.print_r($category, true).'</pre>';
March 25, 201016 yr Author Sure - here you go: ( [0] => stdClass Object ( [term_id] => 29 [name] => Charity Performance [slug] => charityperformance [term_group] => 0 [term_taxonomy_id] => 29 [taxonomy] => category [description] => [parent] => 3 [count] => 1 [object_id] => 1 [cat_ID] => 29 [category_count] => 1 [category_description] => [cat_name] => Charity Performance [category_nicename] => charityperformance [category_parent] => 3 ) [1] => stdClass Object ( [term_id] => 3 [name] => Homepage [slug] => anthony-nolan [term_group] => 0 [term_taxonomy_id] => 3 [taxonomy] => category [description] => [parent] => 0 [count] => 4 [object_id] => 1 [cat_ID] => 3 [category_count] => 4 [category_description] => [cat_name] => Homepage [category_nicename] => anthony-nolan [category_parent] => 0 ) )
March 25, 201016 yr $category = get_the_category(); $term = 9999999; foreach($category as $cat) { $term = ($cat->term_id < $term) ? $cat->term_id ? $term; } echo $term; Try that
March 25, 201016 yr Author Sorry dude: I got this... Parse error: syntax error, unexpected ';' in C:\Program Files\xampp\htdocs\intranet\wp-content\themes\greenroom\sidebar.php on line 5 Line 5: $term = ($cat->term_id < $term) ? $cat->term_id ? $term;
March 25, 201016 yr Oops should have tested lol $term = ($cat->term_id < $term) ? $cat->term_id : $term;
Create an account or sign in to comment