Short code problem
-
I am trying to create a plugin without any prior experience
I want my bar color to change to change if it is over 50
So i used this code to create a short-code which makes a bar and changes its width by my given values, adds a picture and a name of the post and name
This is the short-code i use
[champion name="yasuo" r='90']
However no matter what the value of $r is set to, the color doesn’t change accordingly,
However the width change which uses the same argument works fine .
it seems to not recognize ‘r’ as a valid value, when i change it manually in the code it seems to work.
function champion( $atts ){ $champions=""; // get attibutes and set defaults extract(shortcode_atts(array( 'name' => 'name', 'r' => 0, 'i' => 'This is a general counter, no tips to show.' , ), $atts)); $post = get_page_by_title('' .$name. '', OBJECT, 'post'); $champions = '<div class="champion_table">'; //get image $champions .= '<div id="imagethumb" class="imagethumbnail" >' ; $champions .= '<a href="' . get_permalink( $post->ID ) . '" title="' . esc_attr( $post->post_title ) . '">'; $champions .= get_the_post_thumbnail( $post->ID, 'thumbnail' ); $champions .= '<div class="centered">'.$name.'</div>'; $champions .= '</a>'; $champions .= '</div>'; //bar $champions .= '<div id="bar" class="whole-bar">' ; $champions .= '<div class="percentage-bar" style= width:'.$r.'%>'; //if that i'm having problems with if ($r<='50') { $barcolor="blue"; } else{ $barcolor="violet"; } //it only changes to violet, if i remove 'else' it will only change to blue, no matter what the value of 'r' is $champions .= '<style>.percentage-bar {background-color:'.$barcolor.'}</style></div>'; //ratings $champions .= '<div id="ratings" class="ratings" > '; $champions .= " Counter with <b> $name </b> rating : <bold>".$r."%</bold> "; $champions .= " </div>"; //close divs $champions .= '</div>'; //description $champions .= '<div id ="desc" class="desc">'; $champions .= '<details> <summary>Tips</summary><span style="color: #333333;"><ul>' .$i. '</ul></span></details> <hr>'; $champions .= '</div>'; return $champions; } //add our shortcode add_shortcode('champion', 'champion');
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Short code problem’ is closed to new replies.