是否可以从函数中调用函数。自定义页面或博客中的php?
我把简单函数放在函数中。php:
function testTest()
{
echo "Test";
}
从页面上调用:<?php testTest();?>
但它不起作用。我是否需要制作一个插件,在一个选定的自定义页面中使用这样简单的功能?谢谢你的回答,玛丽
是否可以从函数中调用函数。自定义页面或博客中的php?
我把简单函数放在函数中。php:
function testTest()
{
echo "Test";
}
从页面上调用:<?php testTest();?>
但它不起作用。我是否需要制作一个插件,在一个选定的自定义页面中使用这样简单的功能?谢谢你的回答,玛丽
你可以使用add_shortcode 如果要在编辑器中使用它。
function footag_func() {
return "Test";
}
add_shortcode( \'footag\', \'footag_func\' );
然后在编辑器中使用[footag]。或
在函数中使用这样的代码。php并添加条件标记
add_action( \'loop_start\', \'your_function\' );
function your_function() {
if ( is_singular(\'post\') ) {
echo \'Test\';
}
}
或在函数中创建函数。php
function your_function() {
return \'Test\';
}
然后在模板中使用echo your_function();
您可以快速创建一个快速的快捷代码。
add_shortcode( \'test_shortcode\', \'my_test_callback\' );
function my_test_callback() {
//start adding the echoed content to the output buffer
ob_start();
//run your code here - in this case your testTest() function
testTest();
//return the output buffer
//NOTE: directly echoing the content will give unexpected results
return ob_get_clean();
}
然后,在内容页中添加[test_shortcode]
它将运行您的PHP函数。为了更好地查看短代码,这里有一些有用的链接:
我想要“nextpagelink”短代码[nextpage_shortcode] 我可以将其放入内容中。我见过一些帖子说,由于Wordpress呈现内容的方式,你不能在内容中放置任何与wp\\U link\\u页面相关的内容。正如您所见,“nextpagelink”的文本会根据幻灯片的不同而变化。我希望短代码能够反映这一点。下面是我想做的事情的示意图:两个“开始”按钮都链接到第二张幻灯片。这就是我目前正在研究的内容:function nextpage_shortcode( $atts ) { wp_lin