2
I am using the following code to pass variables through the URL, in wordpress.
if (isset($_GET['layout'])) {
$layout = $_GET['layout'];
} else {
$layout = '1';
}
With $layout
I recover the value in the code, where I use to change the layout style.
By calling this url everything works very well. localhost/wp/? layout=2
In this url there are several links to other posts, pages, categories, etc. I would like that when calling a variable in the URL, the same applies to all links on that page.
For example:
i start calling the variable layout
at the url
thus: localhost/wp/? layout=2
And on this page you will have a link to the "about" page: thus: localhost/wp/about
I wanted the variable layout
be automatically placed on it and all other links.
That way: localhost/wp/about/? layout=2, localhost/wp/other-page/? layout=2, localhost/wp/category/technology/? layout=2
worked, now, the variable "layout" is not the only one that I intend to use: for example this code
var_ = url_.searchParams.get("layout");
to use another variable I would have to duplicate it.– John Quimera
It would be possible to do something like this
url_.searchParams.get("layout", "outra_variavel", "outra");
– John Quimera
I don’t think so. I’m giving another answer because I realized that the
searchParams
does not work in IE.– Sam
rsrs, I imagine, blza then.
– John Quimera
works, you could use multiple vars with your last code?
– John Quimera
I added a solution to the answer.
– Sam
An elegant and professional solution. I have just one more thing, alias, about a point you raised. (recalling that the values of the variables must be numbers according to the
/^(\d){1,}/
): i was already trying here to use words... /?layout=boxed&skin=red is it possible to change this? leave both numbers and words?– John Quimera
This solution is awesome. It even works on IE8.
– John Quimera
a_ = document.body.querySelectorAll("a");
There are some links that I don’t want to take the variable. It is because there are some external links from the gallery, the footer, social links, etc. Links from posts, pages, categories are the ones that should have this effect. I thought about it: #menu ul li a, #list-posts a– John Quimera
a_ = document.body.querySelectorAll(".my-post a, nav a, .menu-top a, .sidebar a");
works perfectly. Thank you– John Quimera
You can use the selector to take all the links you want.
– Sam
I put another related question: https://answall.com/q/277851/95735
– John Quimera