Forum Replies Created

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • in reply to: Nested taxonomies #882
    divinoag
    Member

    Let me try to post once more, maybe today it will let me post.

    I managed to solve my problem as I originally intended. The benefit my method brings is separating the hex color values from the client management, so that people that deal with entering data for clients/posts don’t need to deal with color values. I know my client long enough to know this is for the best, they are not very computer savvy. 🙂

    There were a few things I needed to do to solve the problem. First, my Piklist files had a problem on the scope definition, by removing that I just let Piklist find the scope from where it was being created, which made sure all the variables would save correctly (they weren’t originally, as I found out).

    The rest of the work was all on my theme file. The following is the code I used to pull the information from the database. Please note that I’m a designer, not a developer, so if there is anything about the code that makes you facepalm, please keep that in mind 🙂

    <?php
      // Fetch the complete metadata object for ceu_clients
      $client_meta = get_the_terms( $post->ID, 'ceu_clientes' );
    
      // If a client was not set, skip trying to display the info box
      if ($client_meta && !is_wp_error( $client_meta )) {
    
        // Isolate the term_id for the client
        foreach ( $client_meta as $term ) { $client_ID = $term->term_id; break; }
    
        // Get the ceu_color ID for this client, and the HEX color value for the corresponding ceu_color
        $color_meta = piklist( get_term_custom, $client_ID );
        $color_value = piklist( get_term_custom, $color_meta[ceu_client_color] );
        ?>
    
        <?php // Set the CSS style for this client ?>
        <style type="text/css" media="screen">
          #post-<?php the_ID(); ?> .entry-side-meta .client a { background-color: <?php echo $color_value[ceu_hex_color]; ?>; }
        </style>
    
        <?php // Print the client information ?>
        <?php
        the_terms( $post->ID, 'ceu_clientes', '<div class="client">', '<br>', '</div>' );
      }; ?>
    

    Took some effort, but I think the system works in a very elegant way for the user. Thanks a lot for the help.

    in reply to: Nested taxonomies #879
    divinoag
    Member

    Not sure if my post is going through, maybe because I linked some images it got stuck on moderation? If that happened, I apologize for posting the same thing more than once.

    in reply to: Nested taxonomies #876
    divinoag
    Member

    I should probably post the Piklist files as well:

    Color picker for Colors taxonomy

    <?php
    /*
    Title: Propriedades
    Taxonomy: ceu_colors
    Capability: manage_options
    */
    
    // Let's create a text box field
     piklist('field', array(
       'type' => 'colorpicker'
       ,'scope' => 'post_meta'
       ,'field' => 'ceu_hex_color'
       ,'label' => __('Cor')
       ,'description' => __('Clique na caixa')
       ,'attributes' => array(
         'class' => 'text'
       )
     ));
     ?>

    Dropdown for selecting colors on Client taxonomy

    <?php
    /*
    Title: Propriedades
    Taxonomy: ceu_clientes
    Capability: manage_options
    */
    
    // Let's create a text box field
    piklist('field', array(
        'type' => 'select'
        ,'scope' => 'post_meta'
        ,'field' => 'ceu_client_color'
        ,'label' => 'Cor de destaque'
        ,'description' => 'Cor usada para o fundo de áreas de destaque deste cliente.'
        ,'choices' => piklist(
          get_terms('ceu_colors', array(
            'hide_empty' => false
          ))
          ,array(
            'term_id'
            ,'name'
          )
        )
      ));
     ?>
    in reply to: Nested taxonomies #875
    divinoag
    Member

    Sure. It’s kinda long because I needed to translate the labels to Portuguese.

    // Add custom taxonomy for Clients
    add_filter('piklist_taxonomies', 'ceu_clientes');
    function ceu_clientes($client_taxonomies) {
      $client_taxonomies[] = array(
        'post_type' => 'post'
        ,'name' => 'ceu_clientes'
        ,'show_admin_column' => true
        ,'configuration' => array(
          'hierarchical' => true
          ,'labels' => array(
            'name'                       => _x( 'Clientes', 'taxonomy general name' ),
            'singular_name'              => _x( 'Cliente', 'taxonomy singular name' ),
            'search_items'               => __( 'Buscar' ),
            'popular_items'              => __( 'Populares' ),
            'all_items'                  => __( 'Todos' ),
            'parent_item'                => __( 'Cliente pai' ),
            'parent_item_colon'          => __( 'Cliente pai:' ),
            'edit_item'                  => __( 'Editar' ),
            'update_item'                => __( 'Atualizar' ),
            'add_new_item'               => __( 'Adicionar novo' ),
            'new_item_name'              => __( 'Nome' ),
            'separate_items_with_commas' => __( 'Separe por vírgulas' ),
            'add_or_remove_items'        => __( 'Adicionar ou remover' ),
            'choose_from_most_used'      => __( 'Mais frequentes' ),
            'not_found'                  => __( 'Nenhum cliente encontrado.' ),
            'menu_name'                  => __( 'Clientes' ),
          )
          ,'show_ui' => true
          ,'show_tagcloud' => false
          ,'query_var' => true
          ,'rewrite' => array( 
            'slug' => 'cliente' 
          )
        )
      );
    return $client_taxonomies;
    }
    
    // Add custom taxonomy for Colors
    add_filter('piklist_taxonomies', 'ceu_colors');
    function ceu_colors($color_taxonomies) {
      $color_taxonomies[] = array(
        'post_type' => 'post'
        ,'name' => 'ceu_colors'
        ,'show_admin_column' => true
        ,'hide_meta_box' => true
        ,'configuration' => array(
          'hierarchical' => false
          ,'labels' => array(
            'name'                       => _x( 'Cores', 'taxonomy general name' ),
            'singular_name'              => _x( 'Cor', 'taxonomy singular name' ),
            'search_items'               => __( 'Buscar' ),
            'popular_items'              => __( 'Populares' ),
            'all_items'                  => __( 'Todos' ),
            'parent_item'                => null,
            'parent_item_colon'          => null,
            'edit_item'                  => __( 'Editar' ),
            'update_item'                => __( 'Atualizar' ),
            'add_new_item'               => __( 'Adicionar nova' ),
            'new_item_name'              => __( 'Nome' ),
            'separate_items_with_commas' => __( 'Separe por vírgulas' ),
            'add_or_remove_items'        => __( 'Adicionar ou remover' ),
            'choose_from_most_used'      => __( 'Mais frequentes' ),
            'not_found'                  => __( 'Nenhuma cor encontrado.' ),
            'menu_name'                  => __( 'Cores' ),
          )
          ,'show_ui' => true
          ,'show_tagcloud' => false
          ,'query_var' => true
          ,'rewrite' => array( 
            'slug' => 'cor' 
          )
        )
      );
    return $color_taxonomies;
    }
    
Viewing 4 posts - 1 through 4 (of 4 total)