Forum Replies Created
-
AuthorPosts
-
March 19, 2022 at 5:19 PM in reply to: How to avoid overwriting colors when they are not selected in the custom fields #34608
Valentino
ParticipantHi Long!
That works great! Many thanks!
Last question:
Could this also be implemented with the code I found here: https://metabox.io/wordpress-style-posts-in-particular-category/Code:
<div> function estar_child_output_frontend() { If ( ! is_single() ) { return; } $categories = get_the_category(); $background_color = get_term_meta( $categories[0]->term_id, 'background_color_taxonomy', true ); if ( ! $background_color ) { return; } echo '<style> .single-post { background-color: ' . $background_color . '; } </style>'; } add_action( 'wp_head', 'estar_child_output_frontend' ); </div>If yes, how should I implement it?
March 11, 2022 at 6:07 PM in reply to: ✅Change color style for posts which have a "CUSTOM taxonomy" #34479Valentino
ParticipantHi Long,
it seems to work now.
Thank so much for your help!March 10, 2022 at 10:42 PM in reply to: ✅Change color style for posts which have a "CUSTOM taxonomy" #34459Valentino
ParticipantHi Long, Thanks for your reply. I changed those 2 line code but it doen't work
the <style> doesn't get to the front end.
As I said it worked with WP categories but \it doesn't work with custom taxonomy.This is the custom taxonomy I've made:
<div> <?php add_action( 'init', 'your_prefix_register_taxonomy' ); function your_prefix_register_taxonomy() { $labels = [ 'name' => esc_html__( 'post style color', 'your-textdomain' ), 'singular_name' => esc_html__( 'post style color', 'your-textdomain' ), 'menu_name' => esc_html__( 'Post style color', 'your-textdomain' ), 'search_items' => esc_html__( 'Search post style color', 'your-textdomain' ), 'popular_items' => esc_html__( 'Popular post style color', 'your-textdomain' ), 'all_items' => esc_html__( 'All post style color', 'your-textdomain' ), 'parent_item' => esc_html__( 'Parent post style color', 'your-textdomain' ), 'parent_item_colon' => esc_html__( 'Parent post style color', 'your-textdomain' ), 'edit_item' => esc_html__( 'Edit post style color', 'your-textdomain' ), 'view_item' => esc_html__( 'View post style color', 'your-textdomain' ), 'update_item' => esc_html__( 'Update post style color', 'your-textdomain' ), 'add_new_item' => esc_html__( 'Add new post style color', 'your-textdomain' ), 'new_item_name' => esc_html__( 'New post style color name', 'your-textdomain' ), 'separate_items_with_commas' => esc_html__( 'Separate post style color with commas', 'your-textdomain' ), 'add_or_remove_items' => esc_html__( 'Add or remove post style color', 'your-textdomain' ), 'choose_from_most_used' => esc_html__( 'Choose most used post style color', 'your-textdomain' ), 'not_found' => esc_html__( 'No post style color found', 'your-textdomain' ), 'no_terms' => esc_html__( 'No post style color', 'your-textdomain' ), 'filter_by_item' => esc_html__( 'Filter by post style color', 'your-textdomain' ), 'items_list_navigation' => esc_html__( 'Post style color list pagination', 'your-textdomain' ), 'items_list' => esc_html__( 'Post style color list', 'your-textdomain' ), 'most_used' => esc_html__( 'Most Used', 'your-textdomain' ), 'back_to_items' => esc_html__( 'Back to post style color', 'your-textdomain' ), ]; $args = [ 'label' => esc_html__( 'Post style color', 'your-textdomain' ), 'labels' => $labels, 'description' => '', 'public' => true, 'publicly_queryable' => true, 'hierarchical' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_in_nav_menus' => false, 'show_in_rest' => true, 'show_tagcloud' => false, 'show_in_quick_edit' => true, 'show_admin_column' => false, 'query_var' => true, 'sort' => false, 'meta_box_cb' => 'post_tags_meta_box', 'rest_base' => '', 'rewrite' => [ 'with_front' => false, 'hierarchical' => false, ], ]; register_taxonomy( 'post-style-color', ['post'], $args ); } </div>This is the custom fields I made:
'<div> <?php add_filter( 'rwmb_meta_boxes', 'your_prefix_function_name' ); function your_prefix_function_name( $meta_boxes ) { $prefix = ''; $meta_boxes[] = [ 'title' => __( 'Color style Taxonomy', 'your-text-domain' ), 'id' => 'color-style-taxonomy', 'taxonomies' => ['post-style-color', 'category'], 'fields' => [ [ 'name' => __( 'Background Color', 'your-text-domain' ), 'id' => $prefix . 'background_color_taxonomy', 'type' => 'color', 'columns' => 3, ], ], ]; return $meta_boxes; } </div>'This is the dode I put in the fuctions.php:
<div> // MetaBox color style taxonomy function astr_child_output_frontend() { If ( ! is_single() ) { return; } $term_id = get_queried_object_id(); $background_color = rwmb_meta( 'background_color_taxonomy', ['object_type' => 'term'], $term_id ); if ( ! $background_color ) { return; } echo ' <!-- custom style taxonomy --> <style> .single-post { --bg-color1: ' . $background_color . '; } </style>'; } add_action( 'wp_head', 'astr_child_output_frontend' ); </div>Do you know why it doesn't work?
Valentino
ParticipantOh, I see! Many thanks for your help Long! Now it works.
Valentino
ParticipantHello,
I don't want to make a setting page. I want to be able to set colors for every posts that is why I displayed the custom fields in the post section.I wanted to use it with elementor but your extension doesn't work with it, and you didi find yet a solution, here is the post about it:
https://support.metabox.io/topic/color-picker-doesnt-seem-to-work/?fbclid=IwAR2AC8byNLXJ3eJMKLO9QS2lQTqJUIv40-CWJYs5spqIGtQ7Sx_AqV_vJk4Can you please help me? How can I make this code work:
<div>
--background-color: <?php
$background_color = rwmb_meta( //Change the variable to your desired varible name
'background_color_picker', //Color Picker ID
['object_type' => 'Post'],
'post' ); //Option Name from Settings Page
echo $background_color;
?>;
</div>What should I change in it to make it display the color picker values in the CSS?
Valentino
ParticipantI'm having the same issue here. Color Picker doesn't work on Elementor, any update about this?
-
AuthorPosts