Name: Anonymous 2012-05-24 16:56
I am a Wordpress developer, and I'm buiding a menu that displays items based on what category your in. I counted it as done for about a week, but now I noticed it's displaying the wrong category in some cases. I can't figure out how to code it so this wont happen. I am using a breadcrumb plugin that works flawless, but I'm new to PHP and am having a hard time dissecting the code to apply to my menu. Can anyone steer me in the right direction?
link to the site(notice it's showing the wrong category): http://dev0512.parkingzone.com/blog/store/products/category/collecting-revenue/
The top left menu i created to help me diagnose. It is spitting out the array that my function uses to determine the category. Here is my function for the menu:
/**
* Creates a menu based on the current category
*
*/
function mp_category_menu( $echo = true, $args = '' ) {
global $post;
$terms = get_the_terms($post->ID, "product_category");
$args['taxonomy'] = 'product_category';
$args['echo'] = false;
$args['style'] = 'list';
$args['hierarchical'] = true;
$args['hide_empty'] = 0;
$args['show_option_none'] = __('No Sub-Categories');
foreach ( $terms as $term ) {
if ($term->name == 'Permanent Control'){
$args['child_of'] = 28;
$args['title_li'] = '<h2>Permanent Control</h2>';
}
elseif ($term->name == 'Collecting Revenue'){
$args['child_of'] = 23;
$args['title_li'] = '<h2>Collecting Revenue</h2>';
}
elseif ($term->name == 'First Class Service'){
$args['child_of'] = 26;
$args['title_li'] = '<h2>First Class Service</h2>';
}
elseif ($term->name == 'Gorilla Post'){
$args['child_of'] = 29;
$args['title_li'] = '<h2>Gorilla Post</h2>';
}
elseif ($term->name == 'GreenDrop Recycling'){
$args['child_of'] = 30;
$args['title_li'] = '<h2>GreenDrop Recycling</h2>';
}
elseif ($term->name == 'Reducing Expenses'){
$args['child_of'] = 25;
$args['title_li'] = '<h2>Reducing Expenses</h2>';
}
elseif ($term->name == 'Protecting Revenue'){
$args['child_of'] = 24;
$args['title_li'] = '<h2>Protecting Revenue</h2>';
}
elseif ($term->name == 'Temporary Control'){
$args['child_of'] = 27;
$args['title_li'] = '<h2>Temporary Control</h2>';
}
}
$list = '<ul id="mp_category_list">' . wp_list_categories( $args ) . '</ul>';
if ($echo)
echo $list;
else
return $list;
}
link to the site(notice it's showing the wrong category): http://dev0512.parkingzone.com/blog/store/products/category/collecting-revenue/
The top left menu i created to help me diagnose. It is spitting out the array that my function uses to determine the category. Here is my function for the menu:
/**
* Creates a menu based on the current category
*
*/
function mp_category_menu( $echo = true, $args = '' ) {
global $post;
$terms = get_the_terms($post->ID, "product_category");
$args['taxonomy'] = 'product_category';
$args['echo'] = false;
$args['style'] = 'list';
$args['hierarchical'] = true;
$args['hide_empty'] = 0;
$args['show_option_none'] = __('No Sub-Categories');
foreach ( $terms as $term ) {
if ($term->name == 'Permanent Control'){
$args['child_of'] = 28;
$args['title_li'] = '<h2>Permanent Control</h2>';
}
elseif ($term->name == 'Collecting Revenue'){
$args['child_of'] = 23;
$args['title_li'] = '<h2>Collecting Revenue</h2>';
}
elseif ($term->name == 'First Class Service'){
$args['child_of'] = 26;
$args['title_li'] = '<h2>First Class Service</h2>';
}
elseif ($term->name == 'Gorilla Post'){
$args['child_of'] = 29;
$args['title_li'] = '<h2>Gorilla Post</h2>';
}
elseif ($term->name == 'GreenDrop Recycling'){
$args['child_of'] = 30;
$args['title_li'] = '<h2>GreenDrop Recycling</h2>';
}
elseif ($term->name == 'Reducing Expenses'){
$args['child_of'] = 25;
$args['title_li'] = '<h2>Reducing Expenses</h2>';
}
elseif ($term->name == 'Protecting Revenue'){
$args['child_of'] = 24;
$args['title_li'] = '<h2>Protecting Revenue</h2>';
}
elseif ($term->name == 'Temporary Control'){
$args['child_of'] = 27;
$args['title_li'] = '<h2>Temporary Control</h2>';
}
}
$list = '<ul id="mp_category_list">' . wp_list_categories( $args ) . '</ul>';
if ($echo)
echo $list;
else
return $list;
}