can you please help me how to add a link to php code.
Thing is that I am using a BMI calculator for wordpress and I want to add a link next to a result number.
I know html, but not php...
one slip of a php code where I want to have a link is:
$theme = $attrs['theme'] ?: 'default';
$resultText = $attrs['result'] ?: 'Your BMI is %bmi% ';
$resultText = str_replace('%bmi%', '<span class="bmi-number"></span>', $resultText);
-> I would like to have a link right next to the bmi result number -> 'Your BMI is %bmi% '
Is it possible to do that?
Thanks in advance
答案 0 :(得分:0)
尝试这样做
$BMI = 123;
$resultText = "Your BMI is <a href='YOUR_LINK_HERE'>".$BMI."</a>";
答案 1 :(得分:0)
$BMI = 'click here'; //There can be some code here
$resultText = "Your BMI is <a href='http://your_link.com'>$BMI</a> ";
echo $resultText;
答案 2 :(得分:0)
感谢大家的答案...但是%bmi%是某种变数,因为在页面上我放了一个短代码:
[bmi theme =&#34;默认&#34; heightPlaceholder =&#34;身高&#34;提交=&#34;计算&#34;结果=&#34; BMI无效%bmi%&#34;]
这个%bmi%从表单中计算...以您放置体重和身高的形式而不是得到答案,您可以在测试页面上查看:http://legionargym.si/testna-stran/
向下滑动并查看计算您的BMI
链接到php文件在这里:https://dl.dropboxusercontent.com/u/441444/BMIphpcode.txt
$crawlers_agents = strtolower('Bloglines subscriber|Dumbot|Sosoimagespider|QihooBot|FAST-WebCrawler|Superdownloads Spiderman|LinkWalker|msnbot|ASPSeek|WebAlta Crawler|Lycos|FeedFetcher-Google|Yahoo|YoudaoBot|AdsBot-Google|Googlebot|Scooter|Gigabot|Charlotte|eStyle|AcioRobot|GeonaBot|msnbot-media|Baidu|CocoCrawler|Google|Charlotte t|Yahoo! Slurp China|Sogou web spider|YodaoBot|MSRBOT|AbachoBOT|Sogou head spider|AltaVista|IDBot|Sosospider|Yahoo! Slurp|Java VM|DotBot|LiteFinder|Yeti|Rambler|Scrubby|Baiduspider|accoona');
$crawlers = explode("|", $crawlers_agents);
foreach($crawlers as $crawler) {
if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), trim($crawler)) !== false) {
return true;
}
}
return false;
}
public function __construct() {
if (!$this->is_bot()) {
wp_enqueue_style('bmi-calculator-shortcode-styles', plugin_dir_url(__FILE__).'bmi-calculator-shortcode.css');
wp_enqueue_script('bmi-calculator-shortcode-scripts', plugin_dir_url(__FILE__).'bmi-calculator-shortcode.js', array('jquery'));
}
}
public function processShortcode($attrs) {
$metricText = $attrs['metric'] ?: 'Metrične merske enote';
$imperialText = $attrs['imperial'] ?: 'Imperične merske enote';
$heightText = $attrs['height'] ?: 'Vaša višina';
$weightText = $attrs['weight'] ?: 'Vaša teža';
$heightPlaceholder = $attrs['heightPlaceholder'] ?: 'Višina';
$weightPlaceholder = $attrs['weightPlaceholder'] ?: 'Teža';
$submitText = $attrs['submit'] ?: 'Submit';
$theme = $attrs['theme'] ?: 'default';
$resultText = $attrs['result'] ?: 'Your BMI is %bmi% ';
$resultText = str_replace('%bmi%', '<span class="bmi-number"></span>', $resultText);
$out = <<<HEREDOC