內容簡介
您是否曾想要動態地計算一些數值,以顯示在您的文章中?假設您有一些簡碼(shortcode),可以即時從資料庫檢索數值。現在,您想要對這些簡碼進行一些計算,並在您的文章或頁面中顯示結果。這款外掛允許您使用簡單的 [calculate] 簡碼,加上數學運算式,以即時顯示這些數值!
因此,像 [calculate]2+3*4[/calculate] 這樣的數學運算式將返回值 “14”。現在,只需將任何數值替換為返回數字的簡碼,您就可以完成設置。
屬性
您可以使用 “dec” 屬性來指定您要將結果四捨五入到多少位小數。默認值為 “0”。這意味著,默認情況下,所有結果都會四捨五入為整數。
為了進行國際化的數字格式化,您可以使用 “int” 屬性來指定區域設置。例如,int=”fr_FR” 將根據法國區域設置格式化數字!
有關演示,請參閱屏幕截圖。
例如,您可以使用此功能來顯示正在不斷變化的表格中的值。或者參考動態價格乘以一些值。此外,您可以在這裡看到此外掛在真實網站上的應用實例。
最好的部分是,它不使用 “eval” 等危險的函數,因此所有作者都可以安全地使用它。它不會對您的網站造成破壞。
外掛標籤
開發者團隊
② 後台搜尋「Calculate Values with Shortcodes」→ 直接安裝(推薦)
原文外掛簡介
Have you ever wanted to calculate some values dynamically to display in your posts? Let’s say you have some shortcodes that retrieve values in real time from the database. Now you want to perform some calculations on those shortcodes and display the results in your posts or pages. This plugin allows you to use a simple [calculate] shortcode with the expression inside to display these values in real time!
So an expression like [calculate]2+3*4[/calculate] will return the value “14”. Now just replace any numeric value with a shortcode that returns a number and you’re set.
Attributes
You can use the “dec” attribute to specify the number of decimal digits you want to round the result up to. The default is “0”. Meaning that by default, all results will be rounded to an integer.
For international number formatting, you can use the “int” attribute to specify a locale. For example, int=”fr_FR” will format the numbers according to the french locale!
See screenshots for illustrations.
For example, you can use this to display values in a table that are constantly changing. Or refer to dynamic prices multiplied by some value. The possibilities are endless.
You can see a real world example of this plugin at work here:
The best part is, it doesn’t use dangerous functions like “eval” to work – which means all authors can use it safely. There’s no danger of it breaking your site.
