• Hi guys,

    I am searching a way to display different posts conditioned on a kind of global variable. Like on multilanguage sites. When you press the flag the page changes the language and some images.
    That’s what I am looking for. But not with languages. I want it in general.

    I want to have a landing page where the user klicks on one city. Conditioned on which city he choose he has other images and some other posts.

    I do not know how to call it. Therefore I was not able to google it.
    Do anyone know an elegant way?

    thanks and best regards

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    I’m not sure what to call it either, but I know of one or two ways to handle this, others exist as well.

    When the user makes a selection, this invokes some javascript that saves the selection in a cookie before forwarding the user to your main page. On the PHP side, hook ‘pre_get_posts’ action. Your action callback checks for a cookie value in the super global $_COOKIE (which automatically has cookie values sent by the user’s browser). Set a query var that will include posts related to the user selection when the query runs.

    As a super global, $_COOKIE is available to any PHP code without the need to declare the global, so the value can also be checked on templates to decide what images to retrieve and decide other related output besides querying for posts.

    Storing the user preference as a cookie does mean that if the user should visit your site from another browser, the preference will not be available and they would have to re-select their preference. Alternately, the preference could be stored in user meta. Then their preference would be available no matter where they log in from, but they will then need to log in for their preference to be known.

Viewing 1 replies (of 1 total)
  • The topic ‘Different Pages on a condition – like Multilanguage’ is closed to new replies.