$GLOBALS variable in wordpress to access a value across templates?
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 p开发者_StackOverflowage 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!
You could just save it in the $_SESSION
?
You can use the Transient API to do that sort of thing.
精彩评论