Note that there are some explanatory texts on larger screens.

plurals
  1. POadding image in php
    text
    copied!<p>I have a Wordpress plugin that shows a ratting snippet for Google. 1.0 - 5.0 and I would like to add a image for the value selected, right after the rating, but it doesn't.</p> <p>So far I have got it to load the image but it doesn't show up where I want it to, and that is where I am stuck.</p> <p><a href="http://i.stack.imgur.com/Qxs4Z.gif" rel="nofollow">example pic</a></p> <p>Here is was I tried to add:</p> <pre><code>if ($rating == "5.0"){ print("&lt;IMG SRC ="stars/5-0.png&gt;");} </code></pre> <p>here is the plugin code:</p> <pre><code>&lt;?php $prefix = 'pk_rs_'; DEFINE ('PK_RS_DEFAULT_RATING', '-'); DEFINE ('PK_RS_DISPLAY', true); $pk_rs_meta_box = array( 'id' =&gt; 'pk_rich_snippet_review', 'title' =&gt; 'Google Rich Snippets: Reviews', 'page' =&gt; 'post', 'context' =&gt; 'normal', 'priority' =&gt; 'high', 'fields' =&gt; array( array( 'name' =&gt; 'Rating', 'desc' =&gt; 'Product rating, from 1 to 5.', 'id' =&gt; 'rating', 'type' =&gt; 'select', 'options' =&gt; array('-', '1.0', '1.5', '2.0', '2.5', '3.0', '3.5', '4.0', '4.5', '5.0') ), array( 'name' =&gt; 'Author', 'desc' =&gt; 'Author display name.', 'id' =&gt; 'author', 'type' =&gt; 'text', 'std' =&gt; '' ) ) ); add_action('admin_menu', 'pk_rich_snippet_add_box'); // Add meta box function pk_rich_snippet_add_box() { global $pk_rs_meta_box; add_meta_box($pk_rs_meta_box['id'], $pk_rs_meta_box['title'], 'pk_rich_snippet_show_box', $pk_rs_meta_box['page'], $pk_rs_meta_box['context'], $pk_rs_meta_box['priority']); } // Callback function to show fields in meta box function pk_rich_snippet_show_box() { global $pk_rs_meta_box, $post; // Use nonce for verification echo '&lt;input type="hidden" name="pk_rich_snippet_nonce" value="', wp_create_nonce(basename(__FILE__)), '" /&gt;'; echo '&lt;table class="form-table"&gt;'; foreach ($pk_rs_meta_box['fields'] as $field) { // get current post meta data $meta = get_post_meta($post-&gt;ID, $field['id'], true); echo '&lt;tr&gt;', '&lt;th style="width:20%"&gt;&lt;label for="', $field['id'], '"&gt;', $field['name'], '&lt;/label&gt;&lt;/th&gt;', '&lt;td&gt;'; switch ($field['type']) { case 'text': echo '&lt;input type="text" name="', $field['id'], '" id="', $field['id'], '" value="', $meta ? $meta : $field['std'], '" size="30" style="width:97%" /&gt;', '&lt;br /&gt;', $field['desc']; break; case 'textarea': echo '&lt;textarea name="', $field['id'], '" id="', $field['id'], '" cols="60" rows="4" style="width:97%"&gt;', $meta ? $meta : $field['std'], '&lt;/textarea&gt;', '&lt;br /&gt;', $field['desc']; break; case 'select': echo '&lt;select name="', $field['id'], '" id="', $field['id'], '"&gt;'; foreach ($field['options'] as $option) { echo '&lt;option', $meta == $option ? ' selected="selected"' : '', '&gt;', $option, '&lt;/option&gt;'; } echo '&lt;/select&gt;', '&lt;br /&gt;', $field['desc']; break; case 'radio': foreach ($field['options'] as $option) { echo '&lt;input type="radio" name="', $field['id'], '" value="', $option['value'], '"', $meta == $option['value'] ? ' checked="checked"' : '', ' /&gt;', $option['name']; } break; case 'checkbox': echo '&lt;input type="checkbox" name="', $field['id'], '" id="', $field['id'], '"', $meta ? ' checked="checked"' : '', ' /&gt;', '&lt;br /&gt;', $field['desc']; break; } echo '&lt;td&gt;', '&lt;/tr&gt;'; } echo '&lt;/table&gt;'; } add_action('save_post', 'pk_rs_save_data'); // Save data from meta box function pk_rs_save_data($post_id) { global $pk_rs_meta_box; // verify nonce if (!wp_verify_nonce($_POST['pk_rich_snippet_nonce'], basename(__FILE__))) { return $post_id; } // check autosave if (defined('DOING_AUTOSAVE') &amp;&amp; DOING_AUTOSAVE) { return $post_id; } // check permissions if ('page' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) { return $post_id; } } elseif (!current_user_can('edit_post', $post_id)) { return $post_id; } foreach ($pk_rs_meta_box['fields'] as $field) { $old = get_post_meta($post_id, $field['id'], true); $new = $_POST[$field['id']]; if ($new &amp;&amp; $new != $old) { update_post_meta($post_id, $field['id'], $new); } elseif ('' == $new &amp;&amp; $old) { delete_post_meta($post_id, $field['id'], $old); } } } add_filter('the_content', 'pk_rs_add_rich_snippet_to_content', 20); function pk_rs_add_rich_snippet_to_content($content){ if (is_single()&amp;&amp;!is_feed()){ global $post; $rating = get_post_meta($post-&gt;ID, 'rating', true); $rating = ( '-' == $rating &amp;&amp; '-' != PK_RS_DEFAULT_RATING ) ? PK_RS_DEFAULT_RATING : $rating; if ( '-' != $rating ){ $title = $post-&gt;post_title ; $dateTime = date_create( $post-&gt;post_date ); $date = $dateTime-&gt;format("Y-m-d"); $date_only = $dateTime-&gt;format("M j"); $author = get_post_meta($post-&gt;ID, 'author', true); $author = ( '' == $author ) ? ucfirst(get_the_author_meta('display_name', $post-&gt;post_author)) : $author; $summary = get_post_meta($post-&gt;ID, 'summary', true); $description = get_post_meta($post-&gt;ID, 'description', true); if ( !PK_RS_DISPLAY ) { $output = "&lt;div class=\"hreview\" style=\"display:none\"&gt;"; $output .= "&lt;span class=\"item\"&gt;&lt;span class=\"fn entry-title\"&gt;".$title."&lt;/span&gt;&lt;/span&gt;"; $output .= "Reviewed by &lt;span class=\"reviewer\"&gt;".$author."&lt;/span&gt; on &lt;span class=\"dtreviewed\"&gt; ".$date_only."&lt;span class=\"value-title\" title=\"".$date."\"&gt;&lt;/span&gt;&lt;/span&gt;"; $output .= "Rating: &lt;span class=\"rating\"&gt;".$rating."&lt;/span&gt;"; $output .= "&lt;span class=\"summary\"&gt;".$summary."&lt;/span&gt;"; $output .= "&lt;span class=\"description\"&gt;".$description."&lt;/span&gt;"; $output .= "&lt;/div&gt;"; } else { $output = "&lt;div class=\"hreview\" style=\"display:block; margin: 0 0 10px 10px; padding: 10px; background: #F6F6F6; border: 1px solid #DDD; -moz-border-radius: 3px; border-radius: 3px; font-size: 0.8em; width: 30%; float: right;\"&gt;"; $output .= "Title: &lt;span class=\"item\"&gt;&lt;span class=\"fn entry-title\" style=\"font-size: 0.8em;font-weight: normal;\"&gt;".$title."&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;"; $output .= "Reviewed by &lt;span class=\"reviewer\"&gt;".$author."&lt;/span&gt; on &lt;span class=\"dtreviewed\"&gt; ".$date_only."&lt;span class=\"value-title\" title=\"".$date."\"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br/&gt;"; $output .= "Rating: &lt;span class=\"rating\"&gt;".$rating."&lt;/span&gt;&lt;br/&gt;"; $output .= ( 0 &lt; strlen($summary) ) ? "Summary: &lt;span class=\"summary\"&gt;".$summary."&lt;/span&gt;&lt;br/&gt;" : ""; $output .= ( 0 &lt; strlen($description) ) ? "&lt;p&gt;&lt;span class=\"description\"&gt;".$description."&lt;/span&gt;&lt;/p&gt;" : ""; $output .= "&lt;/div&gt;"; } $content = $output.$content ; } } return $content; } ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload