Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

PHP Arrays

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;
}

Name: Anonymous 2012-05-24 16:59

I'm new to PHP
Flee while you still can.

Name: Anonymous 2012-05-24 17:01

No choice, It' like the main scripting language for the web

Name: Anonymous 2012-05-24 17:02

I'm a Wordpress developer
I'm new to PHP

?

Name: Anonymous 2012-05-24 17:04

I mostly style things and tweak plugins. This is the first project I've had where the plugin just doesn't do what I need it to

Name: Anonymous 2012-05-24 17:13

I doubt anyone here uses shitpress.

Look at doc to see how to correctly use it:
http://codex.wordpress.org/Function_Reference/get_the_terms
http://codex.wordpress.org/Template_Tags/wp_list_categories

Name: Anonymous 2012-05-24 17:15

I've been all thru those. I'm missing something clearly. I don't have enough of a php knowledge to understand how to apply the stuff

Name: Anonymous 2012-05-24 17:17

>>7

first of all you are not safe guarding against the return types


$terms = get_the_terms( $post->ID, 'on-draught' );
                       
if ( $terms && ! is_wp_error( $terms ) )

Name: Anonymous 2012-05-24 17:34

When I try and add that in I just get a bunch of syntax errors

Name: Anonymous 2012-05-25 12:52

Wordpress
fuck off and learn real programming, php fagstorm

Name: bampu pantsu 2012-05-29 5:09

bampu pantsu

Don't change these.
Name: Email:
Entire Thread Thread List