1

I'm trying to modify the way my WordPress template displays content depending on the URL parameters. The first stage is to catch variables and store them for subsequent pageviews so that the user has a consistent layout of the site for their entire session.

<script>
// Parse the URL
function getURLParameter(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
    results = regex.exec(location.search);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

islayout = getURLParameter('layout');

if(islayout == "layout1") {
    localStorage.setItem("layoutvalue", 1);
}
else if(islayout == "layout2") {
    localStorage.setItem("layoutvalue", 2);
}
else if(islayout == "reset") {
    localStorage.setItem("layoutvalue", 0);
}
else {
    var layoutvalue = 0;
}
</script>

Now, I just need to know how to pass these variables to the PHP level in wordpress so certain segments in the PHP code don't load on the site. However, the tricky part comes into play because my site is cached.

When I tried passing the variables through PHP and had caching enabled... User 1 (URL parameter = layout1) would set the settings for all following pageviews and seesions from other users. Then when user 2 would come along, they'd see the cached page layout which was set by user 1.

How can I have caching enabled but still allow them to all see a layout that's unique to them.

Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.