Php 是否可以在模板文件-Wordpress中定义快捷码和cal
我有一个文件a.php,其中定义了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
我已经创建了一个自定义模板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]"); ?>