dongxuan2015 2013-10-09 06:23
浏览 22
已采纳

使用wordpress,如何使用永久链接传递变量

Here's the scenario:

A visitor to my site lands on restricted content. I provide a link to the membership options/signup page. Upon completion of signup, I want to redirect the user back to the page they were viewing.

The membership software I'm using (s2member) provides an success=(url) option, so I really just need to send the permalink of the page they were viewing to the signup page.

The restricted content uses a template file, in which I include a signup link (if they do not currently meet membership requirements). I'm trying to use the wpfunction: add_query_arg.

So, I have:

<a href="<?php echo add_query_arg( '$prev_page', get_permalink(), get_permalink( 67847 ) ); ?>">Sign Up</a>

And on the page this links to I see

http:///www.mysite.com/member-sign-up/?$prev_page=http://the-correct-permalink-pf-previous-page/

The problem is, on the memebership page, when I

var_dump( $prev_page ); 

it returns

null

Is this the correct method for sending a variable using a link?

  • 写回答

1条回答 默认 最新

  • drqyxkzbs21968684 2013-10-09 06:32
    关注

    Variables are not interpolated inside single quotes. Single quoted strings will display things almost completely as is. Change it to double quotes if you want the actual variable value to be used:

    <a href="<?php echo add_query_arg( "$prev_page", get_permalink(), 
    get_permalink( 67847 ) ); ?>">Sign Up</a>
    

    And now, you can access the query parameter in your membership page, like so:

    $var = $_GET['foo']; // where 'foo' == $prev_page
    echo $var;
    

    However, if you're actually trying to use the literal string $prev_page as your query parameter, you can simply do the following in your membership page:

    $_GET['$prev_page']; // note the single-quotes
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部