dongtuo6562 2011-09-13 18:22
浏览 78

wordpress中的$ GLOBALS变量可以跨模板访问值吗?

In wordpress, is there a way to store a value (specifically, a permalink URL string) in a variable that I can access across template files?

What I need to do is this: in one of my wordpress single page templates, I need to create a link to the source page that brought the user there.

Since there are a number of different pages across the site that could have sent the user to this page, the solution that occurred to me was to store the permalink of the source page in some sort of a global variable that could be accessed by the destination page template. This would allow me to create a link back to the source page.

I googled for solutions and found one: On each of my source pages, I do this:

$GLOBALS['my_variable'] = get_permalink($post->ID); 

and then on the destination page template, I do this:

<a href="<?php echo $GLOBALS['my_variable']; ?>">Back</a>

But this doesn't work. The variable gets set correctly in the source page template, but on the destination page, somehow the variable ends up getting replaced by the permalink of that (destination) page every time. I can't figure out why. Some help please!

  • 写回答

2条回答 默认 最新

  • dongpu2727 2011-09-13 18:26
    关注

    You could just save it in the $_SESSION?

    评论

报告相同问题?

悬赏问题

  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线