A
A
Alexander Erik2015-06-25 15:59:55
User navigation
Alexander Erik, 2015-06-25 15:59:55

How to implement site regionalization in WordPress?

6bbef51ec4c846868d173a1534efbd13.png
How can I implement the regionality of the site on WordPress 4?
While solving the problem, I ran into problems:

  1. If you organize the taxonomy according to the principle: "site.ru/city/category/page", then cities will be displayed in the main menu, and the categories will be their submenus.
    How to make it so that in a custom menu in the site header you can select a city, and then:
    • the path would change, for example, to "site.ru/moskva/"
    • the navigation menu would change to the fact that in a particular city
    • did the widget with the address and phone number in the header change the one set for the city?

  2. Problems with the same slugs of pages and posts.
    For example: "site.ru/moskva/page" and "site.ru/newyork/page", where "moskva" and "newyork" are taxonomy categories in WordPress, and "page" is a page.
Perhaps there are some ready-made and good solutions and plugins for this task?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Erik, 2015-07-17
@goodee

Played around a bit and fixed the problem.
First, the problem with the same page slugs in WordPress:
Everything is ridiculously simple, we create pages, and select the "Parent element" of the necessary ones.
For example:
site.ru/moskva/article
site.ru/kazan/article
where moskva and kazan are the parent pages of two different article pages respectively.
With this, everything is simple and clear.
Next, I created "custom fields" for the city pages - "tel" and "address".
WordPress added the following lines to the functions.php of the theme:

// узнаем самый первый родительский элемент (страницу города)
function parent_postID() {
  global $post;
  $postID = $post->ID;
  if ($post->post_parent) {
    $anc = get_post_ancestors($postID);
    $root = count($anc)-1;
    $parentID = $anc[$root];
  } else {
    $parentID = $postID;
  }
  return $parentID;
}

// узнаем самую корневую страницу
function show_gorod() {
  global $post;
  $postID = $post->ID;
  $parentID = parent_postID();
  if (!is_front_page() and ($parentID or $postID)) {
    $city_name = get_the_title($parentID);
    $city_link = get_the_permalink($parentID);
    $city_class = 'gorod';
    $city_string = '<a class="'.$city_class.'" href="'.$city_link.'">'.$city_name.'</a>';
  } else {
    $city_name = 'Выберите город:';
    $city_class = 'gorod small';
    $city_string = '<p class="'.$city_class.'">'.$city_name.'</p>';
  }

  return $city_string;
}

After that, on any child page and the city page, the information recorded in the parent page was displayed.
It was enough to specify in the template <?php echo show_gorod() ?>
and the necessary information was displayed.
So thank you all for your replies/advice *sarcasm*.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question