• Resolved Cat

    (@stitchyrocks)


    Hi,

    I’m generating the color palette on my page in the php like so:

    <?php 
    						$i = 0;
    						$max_iterations = 6;
    						$colors = get_the_terms( $post_thumbnail_id, 'cpg_palette');
    						if ( $colors && !is_wp_error( $colors ) ) :
    							$color_array = array();  
    							foreach ( $colors as $color ) :
    								if ($i < $max_iterations) :
    									$color_array[$i] = $color->slug; 
    									$i++;
    								endif; 
    							endforeach;
    						endif; 
    						foreach ( $color_array as $color ) : ?>
    					 		<a href="<?php echo esc_url( get_bloginfo( 'url' ) . '/color/' . $color) ?>" style="background: #<?php echo $color; ?>;"></a>
    						<?php endforeach; ?>

    I’m not sure how to code the URL for the color so that clicking on it would take the user to an archive page of the closest dominant color?

    • This topic was modified 6 years, 4 months ago by Cat.
Viewing 1 replies (of 1 total)
  • Plugin Author Houke de Kwant

    (@houkedekwant)

    We don’t support linking to all colors, for that you should build your own solution. What we do is bundling colors in an table with readable color names (you can check the color table by the plugin settings to see the colors we map by default).

    If you go for example to yoururl.com/color/black you will see all images related to black.

    To test this, you can do the following:
    1) At the plugin settings (Media > Color Palette Generator) you can check ‘Should the palette colors link to the search page?’.
    2)Now when you add a shortcode like this [colorpalette attachment="XX" colors="10" size="thumbnail"] to your page (where XX is the id of an attachment with a generated palette). You will see the link we generate for each color.

    That are the colors we support (20 in total).

    In order to apply this in your code, it would be something like this

    
    $colors = get_the_terms( $att_id, 'cpg_dominant_color' );
    $dominant = $colors[0];
    $parent = get_term( $dominant->parent, 'cpg_dominant_color' );
    $dominant = $dominant->name;
    
    $output = '<a href="'.esc_url( get_bloginfo( 'url' ).'/color/'.$parent->description.'/' ).'">'.esc_attr($dominant).'</a>';
    
Viewing 1 replies (of 1 total)
  • The topic ‘Color link’ is closed to new replies.