Transferring data between Wordpress pages

I have a menu, when the user clicks on any menu item, I want to transfer them to one page, but I want to style the page differently depending on the menu item ... for example: change the background color To be different. What is the best way to do this? I thought that when they click on a menu item, you can set a variable or set a session variable.

Is there an easier way to do this? Does Wordpress have anything built into the architecture to make it easier?

+3
source share
2 answers

Do not use a session for this. Because HTTP is a stateless protocol, you should avoid using the longest session. Since the user clicks on the link, it only makes sense to make this link the information you submit. Just pass whatever data you want in the url for example. as a query string parameter:

  • http://example.com/page_x?bgcolor=1
  • http://example.com/page_x?bgcolor=2
  • http://example.com/page_x?bgcolor=3

Then you can simply request this in the template page like this:

<?php
  /*
  Template Name: Varying Background Color Template
  */

  $bgcolor = $_GET['bgcolor'];

  switch ($bgcolor) {
    case 1:
      // Change the background to color 1
      break;

    case 2:
      // Change the background to color 2
      break;

    case 3:
      // Change the background to color 3
      break;
  }
?>

, , , "" WordPress, . , , , WordPress.

+5
  • wp ( ) (. )
  • . . ...

, .

-2

Source: https://habr.com/ru/post/1761228/


All Articles