Note that there are some explanatory texts on larger screens.

plurals
  1. POdisplay a calulated value on all post in a category in wordpress
    primarykey
    data
    text
    <p>i am working on wordpress based coupon site. I have to create a amount calculator which would work on all the individual category pages . I would be having a amount slider which would be having $ values.</p> <p>Once a value is selected and on clicking the submit button, i want the percentage deals (under that respective category) to calculate a amount with respect to the $ amount selected using the slider. and then displaying it on their respective deals. I hope the idea is clear.</p> <p>Till now, i have managed to, take all the posts title of the current category page into an array, and then using the preg_match feature, i have managed to extract out the '%' deal amount. Also i have created a simple slider which the user will need to input their $ amount. </p> <pre><code>&lt;?php $array = array(); global $post; $category = get_the_category($post-&gt;ID); $category = $category[0]-&gt;cat_ID; $myposts = get_posts(array('numberposts' =&gt; 1, 'offset' =&gt; 0, 'category__in' =&gt; array($category), 'post_status'=&gt;'publish')); foreach($myposts as $post) : setup_postdata($post); $title = get_the_title(); array_push($array,$title); endforeach; ?&gt; &lt;?php wp_reset_query(); ?&gt; &lt;?php foreach($array as $str) { if(preg_match('/(\d+)\%/i' ,$str,$m)) { echo $m[1],"\n"; ?&gt; &lt;input type="text" name="a" value="&lt;?php echo $m[1]; ?&gt;" size=5&gt; &lt;?php } } ?&gt; </code></pre> <p>the above code is used to fetch all the post under the current category and extracting the % value from the respective post title. The extracted number is in '$m[1]' which i would like to pass against the respective post.</p> <p>I am not able to define the respective post and passing that '%' amount and in return sending the calculated amount and saving it back to that particular post. that is, on clicking the submit button, i would want that each post having percentage value would get calculated and get displayed against that particular post. Sorry for such a huge explanation. I didnt want any detail to get missed out. Any help would be appreciated.</p> <p>EDITED CODE - This code is responsible to display a single deal. I have placed the above mentioned in the sidebar file of my theme. I want to display the savings within the respective percentage deal.</p> <pre><code> &lt;div style="float:left; &lt;?php if($GLOBALS['themename']['display_previewimage'] =="yes"){ ?&gt;width:357px;&lt;?php }else{ ?&gt;width:477px;margin-left:10px;&lt;?php } ?&gt;"&gt; &lt;h2 class="coupontitle"&gt; &lt;a href="&lt;?php echo $link; ?&gt;" title="&lt;?php the_title_attribute(); ?&gt;" &lt;?php if($GLOBALS['premiumpress']['analytics_tracking'] =="yes"){ ?&gt;onclick="pageTracker._trackEvent('COUPON CLICK', 'TITLE CLICK', '&lt;?php the_title(); ?&gt;');"&lt;?php } ?&gt; &lt;?php if(is_single()){ ?&gt; target="_blank"&lt;?php } ?&gt;&gt; &lt;?php the_title(); ?&gt; &lt;/a&gt; &lt;/h2&gt; &lt;p&gt;&lt;?php echo $post-&gt;post_content; ?&gt;&lt;/p&gt; &lt;?php if($code != "" &amp;&amp; $GLOBALS['themename']['system'] =="link"){ ?&gt; &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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