Tagged: 

Viewing 9 reply threads
  • Author
    Posts
    • #873
      divinoag
      Member

      Hello, first of all thanks for making this plugin, it does make our lives easier in so many way. 🙂

      I have a somewhat weird and complicated setup that maybe is completely unnecessary, but it was the best way I could think of. My client, a PR company wanted their blog to display uniquely colored tags to show that each post is about each of their clients.

      My concept for this setup, to allow for maximum customization, is to add a custom taxonomy

      ceu_clients

      for posts, with the list of all their clients. To allow for the colors the easiest way would be to add a new field with a color picker, but there is a catch: the company has a specific color palette they wanted to use, and while they can add more eventually they wanted to keep this open.

      So my idea was to create another taxonomy

      ceu_colors

      where they can set a color hex value for each unique color name. I then added this taxonomy as a dropdown selector to the first taxonomy, so you can select a color name for each client.

      So far so good, I was able to set that up and it seems to save correctly. My issue now is: how do I get the hex color value set for a particular client on my theme? Pulling the value of

      ceu_clients

      on my theme (get_the_terms( $post->ID, ‘ceu_clients’)) doesn’t display any reference to the

      ceu_colors

      taxonomy, so I’m not 100% positive it is setup correctly.

      Am I on the right track, or am I missing anything important?

      Thanks for the attention.

    • #874
      Steve
      Keymaster

      Can you post your Taxonomy code?

    • #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;
      }
      
    • #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'
            )
          )
        ));
       ?>
    • #877
      Steve
      Keymaster

      I’m just a little confused. Is ceu_clients a dropdown of client names associated with the post, and then ceu_colors would be a dropdown of colors?

      Or do you just want to associate a Color with a dropdown of client names?

    • #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.

    • #880
      Steve
      Keymaster

      Nothing came through. Please post again.

    • #881
      Steve
      Keymaster

      Thanks for sending over this explanation.

      I think you have a very cool idea, but it may be more complicated then you need. Why not put the Color Picker as a custom field on the ceu_clientes taxonomy. When you want to assign RED to “The Client”, just edit “The Client” and choose the color from the color picker.

      Piklist then has a function to pull term_meta:
      piklist(get_term_custom,$term_id);

      Use it like this:
      $termmeta = piklist(get_term_custom,$term_id);

      Then user print_r to see the data:
      print_r($termmeta);

      You should see an array of fields and data, which should help you pull the correct field.

    • #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.

    • #883
      Steve
      Keymaster

      This is really nice. Good job!

Viewing 9 reply threads
  • You must be logged in to reply to this topic.