Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 是否可以在模板文件-Wordpress中定义快捷码和cal_Php_Wordpress - Fatal编程技术网

Php 是否可以在模板文件-Wordpress中定义快捷码和cal

Php 是否可以在模板文件-Wordpress中定义快捷码和cal,php,wordpress,Php,Wordpress,我有一个文件a.php,其中定义了 我已经创建了一个自定义模板custom.php,并在wordpress后端创建了一个页面,页面id=11 因此,从a.php我在page\u id的帮助下将用户发送到custom.php,然后获取key=123 这很好用 唯一的问题是我不确定第11页的内容 是否可以使用快捷码获得相同的结果,以避免在模板文件中使用页面id。函数创建快捷码以获取页面id function id_shortcode( $atts ) { // extract the var

我有一个文件a.php,其中定义了

我已经创建了一个自定义模板custom.php,并在wordpress后端创建了一个页面,页面id=11

因此,从a.php我在page\u id的帮助下将用户发送到custom.php,然后获取key=123

这很好用

唯一的问题是我不确定第11页的内容


是否可以使用快捷码获得相同的结果,以避免在模板文件中使用页面id

函数创建
快捷码
以获取
页面id

function id_shortcode( $atts ) {
    // extract the variables, if there is no ID attr, the default is 1
    extract( shortcode_atts( array(
        'id' => 1
    ), $atts ) );
    // set page id to either the id attr which defaults to one.
    $page_id = $id;
    $page_data = get_page( $page_id );
    return 
}
// shortcode registration
add_shortcode( 'getid', 'id_shortcode' );
然后,您只需在页面上使用
[getid]
快捷码
,即可获得该
页面id

function id_shortcode( $atts ) {
    // extract the variables, if there is no ID attr, the default is 1
    extract( shortcode_atts( array(
        'id' => 1
    ), $atts ) );
    // set page id to either the id attr which defaults to one.
    $page_id = $id;
    $page_data = get_page( $page_id );
    return 
}
// shortcode registration
add_shortcode( 'getid', 'id_shortcode' );
我希望我已经理解并解决了你的问题

您也可以在模板文件中调用此短代码

<?php echo do_shortcode("[getid]"); ?>