Answer the question
In order to leave comments, you need to log in
How to embed a calculator in wordpress on a specific page?
I have a calculator written in Js. And I need to insert it on two pages in wordpress.
<script type="text/javascript">
var section = document.getElementsByTagName("section")[0];
var cont = document.createElement("div");
var div_p = document.createElement("div");
var div_f = document.createElement("div");
section.appendChild(cont);
cont.appendChild(div_p);
cont.appendChild(div_f);
cont.style.width = 520;
cont.style.height = 250;
cont.style.position = 'relative';
cont.style.border = 'outset';
cont.style.marginbottom: 20;
div_p.style.width = '50%';
div_p.style.position = 'absolute';
div_p.style.Float = 'left';
div_p.style.marginTop = 20;
div_p.style.marginLeft = 20;
div_f.style.Float = 'right';
div_f.style.marginTop = 20;
div_f.style.marginLeft = 280;
div_f.style.width = '50%';
div_f.style.position='relative';
div_p.innerHTML = "Сумма кредита:<br>Общий годовой процент по кредиту:<br>Срок кредита:<br><br><br>"+
"Ваш ежемесячный платеж:<br>Общая сумма платежей:<br>Переплата по кредиту составляет:";
div_f.innerHTML = "<form name='credit'><input name='sum' type='text' value='' size=12>"+
"<select type='menu' name='usr' id='curr'><option value='rub'> ман.<option value='USD'>дол."+
"<option value='Eur'>евро</select><br><input name='perc' type='text' value='' size=12>%<br>"+
"<input type='text' value='' name='term' size=12><select type='menu' name='ust' id='ust'>"+
"<option value='month'> мес.<option value='year'> год</select>"+
"</form><button onclick='count()' value='' style='float:left;'>Считать</button><br>"+
"<form name='result' style='margin-top: 8px' ><input name='month_p' type='text' value='' size=24 ' onfocus='this.blur()'><br>"+
"<input name='total_p' type='text' value='' size=24 onfocus='this.blur()'><br>"+
"<input name='over_p' onfocus='this.blur()'type='text' value='' size=24>";
function count() {
var sum = document.credit.sum.value;
var perc = document.credit.perc.value;
var i = new Array(1,12);
var term = document.credit.term.value*i[document.credit.ust.selectedIndex];
var p = perc/1200;
var a = p*Math.pow((1+p),term)/(Math.pow((1+p),term)-1); //Math.pow - возведение в степень (арг-т, степень)
a = (Math.ceil(a*10000))/10000;
var month_p = a*sum;
var total_p = term*month_p;
var over_p = total_p-sum;
var sel_val = new Array ("ман.", "долл.", "евро");
var val = sel_val[document.credit.usr.selectedIndex];
document.result.month_p.value = (Math.round(month_p*100))/100+" "+val;
document.result.total_p.value = (Math.round(total_p*100))/100+" "+val;
document.result.over_p.value = (Math.round(over_p*100))/100+" "+val;
}
</script>
Answer the question
In order to leave comments, you need to log in
int[] arr = new int[8];
There are several options:
1. In the page.php template (single.php if there is no first one), we set the is_page (id) check and the corresponding code in it
2. In functions.php, we wrap all the code as a function, we hang the function on the shortcode, we insert the shortcode in the visual editor on the necessary pages
3. We write a simple plugin (or in functions.php) - we intercept the IDs of the necessary pages at the request level and insert the necessary code on the fly - after the_content() or in the footer, in general, where it should be
UPDATE:
4. In principle, you can remove this entire script from script tags to an external js file and add it to wp_enqueue_script () with the appropriate check is_page (X)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question