Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.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中使用插件机制制作页面接收器?_Php_Wordpress - Fatal编程技术网

Php 如何在Wordpress中使用插件机制制作页面接收器?

Php 如何在Wordpress中使用插件机制制作页面接收器?,php,wordpress,Php,Wordpress,我正在构建一个wordpress插件,这是我的shortcode,我想在我的帖子中使用[phx amount=“20”color=“green”]来呈现一个锚链接,单击该链接将指向一个页面,该页面可以接收get参数并执行一些操作。我已经制作了短代码,但是如何使用插件机制制作这样的页面呢 add_shortcode( 'phx', array( $this, 'phx_shortcode' ) ); function phx_shortcode( $attrs ) { $html = '

我正在构建一个wordpress插件,这是我的
shortcode
,我想在我的帖子中使用
[phx amount=“20”color=“green”]
来呈现一个锚链接,单击该链接将指向一个页面,该页面可以接收
get
参数并执行一些操作。我已经制作了
短代码
,但是如何使用插件机制制作这样的页面呢

add_shortcode( 'phx', array( $this, 'phx_shortcode' ) );

function phx_shortcode( $attrs ) {
    $html = '';
    $customized_atts = shortcode_atts( array(
        'amount' => '10',
        'color'  => 'green',
        ), $attrs, 'phx');

    $html .= "<a href='http://wordpress.dev?".
             "amount={$customized_atts['amount']}'>Pay</a>";

    return $html;
}
add_shortcode('phx',array($this,'phx_shortcode'));
函数phx_短代码($attrs){
$html='';
$customized_atts=短码_atts(数组)(
“金额”=>“10”,
“颜色”=>“绿色”,
),$attrs,'phx');
$html.=”;
返回$html;
}

您的代码可以很容易地插入自定义插件。您只需将自定义插件放入站点的
wp content/plugins
文件夹中,并在登录时启用它。然后该功能将可用于您的WP站点

下面是一个带有副标题的示例标题,我喜欢这样做以增强代码可读性(注意:副标题不是必需的,但主标题是):

/*
插件名称:我的自定义插件
插件URI:http://www.example.com/
说明:我的插件做什么
版本:0.1.0
作者:凤凰
作者URI:http://example.co
许可证:CC属性共享许可证
许可证URI:https://creativecommons.org/licenses/by-sa/4.0/
*/
/*
##################################
###########短代码###########
##################################
在此特别说明此函数的作用。
*/
添加_短码('phx',数组($this,'phx_短码'));
函数phx_短代码($attrs){
$html='';
$customized_atts=短码_atts(数组)(
“金额”=>“10”,
“颜色”=>“绿色”,
),$attrs,'phx');
$html.=”;
返回$html;
}

您的代码可以很容易地插入自定义插件。您只需将自定义插件放入站点的
wp content/plugins
文件夹中,并在登录时启用它。然后该功能将可用于您的WP站点

下面是一个带有副标题的示例标题,我喜欢这样做以增强代码可读性(注意:副标题不是必需的,但主标题是):

/*
插件名称:我的自定义插件
插件URI:http://www.example.com/
说明:我的插件做什么
版本:0.1.0
作者:凤凰
作者URI:http://example.co
许可证:CC属性共享许可证
许可证URI:https://creativecommons.org/licenses/by-sa/4.0/
*/
/*
##################################
###########短代码###########
##################################
在此特别说明此函数的作用。
*/
添加_短码('phx',数组($this,'phx_短码'));
函数phx_短代码($attrs){
$html='';
$customized_atts=短码_atts(数组)(
“金额”=>“10”,
“颜色”=>“绿色”,
),$attrs,'phx');
$html.=”;
返回$html;
}
您将希望使用向WordPress注册查询变量

完成后,您可以使用检索

在主题(
functions.php
)或插件中:

function my_custom_query_vars_filter($vars) {
    $vars[] = 'amount';
    $vars[] .= 'color';
    return $vars;
}
add_filter( 'query_vars', 'my_custom_query_vars_filter' );
在模板文件或其他地方:

$color = get_query_var('color');

$amount = get_query_var('amount');
您需要使用来向WordPress注册查询变量

完成后,您可以使用检索

在主题(
functions.php
)或插件中:

function my_custom_query_vars_filter($vars) {
    $vars[] = 'amount';
    $vars[] .= 'color';
    return $vars;
}
add_filter( 'query_vars', 'my_custom_query_vars_filter' );
在模板文件或其他地方:

$color = get_query_var('color');

$amount = get_query_var('amount');

嗨,谢谢,但我不是这个意思。我希望锚定链接:可以在我的(这个)插件中检索。将“amount”参数更改为20,否?还是希望amount参数是一个动态变量集?嗨,谢谢,但我不是这个意思。我希望锚定链接:可以在我的(这个)插件中检索。将“amount”参数更改为20,否?还是希望amount参数是动态设置的变量?