L
L
Legal Adviser2019-04-11 20:15:24
User navigation
Legal Adviser, 2019-04-11 20:15:24

How to implement a menu in WP?

How to implement a menu? What will be the advice, recommendations? It is very interesting to understand how it is easier to do and so that there is a minimum load on the server.
Example 1: https://notarius-moscow.ru/katalog/okrug/1/
Example 2: https://mnotaries.ru/739
The meaning is this:
There is a page, say "toys" , when you go to the address: we see a menu :
https://example.ru/igrushki/

<ul>
<li><a href="">игрушки 1</a></li>
<li><a href="">игрушки 2</a></li>
<li><a href="">игрушки 3</a></li>
</ul>

go to Toys 1, and see again the menu at:https://example.ru/igrushki/igrushki_1/
<ul>
<li><a href="">игрушки 1.1</a></li>
<li><a href="">игрушки 1.2</a></li>
<li><a href="">игрушки 1.3</a></li>
</ul>

go to toys 1.1, and see again the menu at:https://example.ru/igrushki/igrushki_1.1/
<ul>
<li><a href="">игрушки 1.1.1</a></li>
<li><a href="">игрушки 1.1.2</a></li>
<li><a href="">игрушки 1.1.3</a></li>
</ul>

go to toys 1.1.1, and see the custom entry at:
https://example.ru/igrushki/igrushki_1.1/igrushki_1.1.1/super_igrushki/

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aricus, 2019-04-12
@Aricus

I am not a big expert in wordpress, but since there are no other answers, I will give my code from the topic. Here is the menu on the rubric level 2 page, including neighboring rubrics and entries of this rubric:

$current_cat_id = get_query_var('cat');
  $parent_cat = get_category(get_category($current_cat_id)->parent);
  $categories = get_categories(array(
    'orderby' => 'id',
    'parent' => $parent_cat->term_id,
    'hide_empty' => false,
  ));
  echo '<nav class="aside-panel"><ul>';
  foreach ($categories as $category) {
    if ($category->term_id == $current_cat_id) $isThisCat = true;
    else $isThisCat = false;
    echo '<li class="panel-item';
      if ($isThisCat) echo ' is-active';
    echo '">
      <a href="' .get_category_link ($category->term_id). '" class="label">' .writeTitle($category->name). '</a>';
      if ($isThisCat) {
        echo '<ul class="drop-menu">';
          if ( have_posts() ){
            while (have_posts()) { the_post();
              echo '<li><a href="' .get_the_permalink(). '" class="link">' .nobrArticle(get_the_title()). '</a></li>';
              
            }
          }
        echo '</ul>';
      }
    echo '</li>';
  }
  echo '</ul></nav>';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question