Please tell me the solution for displaying a site map based on the menu.

For example, there is a menu:

ΠšΡ€Π°ΡΠΎΡ‚Π° (Ρ€ΡƒΠ±Ρ€ΠΈΠΊΠ° id=1) Π›ΠΈΡ†ΠΎ (Ρ€ΡƒΠ±Ρ€ΠΈΠΊΠ° id=2) ЛСкарства (Π°Ρ€Ρ…ΠΈΠ² ΠΏΡ€ΠΎΠΈΠ·Π²ΠΎΠ»ΡŒΠ½ΠΎΠ³ΠΎ post_type) Π’Π΅Π»ΠΎ (страница id=3) 

Need to withdraw:

 ΠšΡ€Π°ΡΠΎΡ‚Π° (Ρ€ΡƒΠ±Ρ€ΠΈΠΊΠ° id=1) всС записи Ρ€ΡƒΠ±Ρ€ΠΈΠΊΠΈ id=1 Π›ΠΈΡ†ΠΎ (Ρ€ΡƒΠ±Ρ€ΠΈΠΊΠ° id=2) всС записи Ρ€ΡƒΠ±Ρ€ΠΈΠΊΠΈ id=2 ЛСкарства (Π°Ρ€Ρ…ΠΈΠ² ΠΏΡ€ΠΎΠΈΠ·Π²ΠΎΠ»ΡŒΠ½ΠΎΠ³ΠΎ post_type=example) всС записи post_type=example Π’Π΅Π»ΠΎ (страница id=3) всС Π΄ΠΎΡ‡Π΅Ρ€Π½ΠΈΠ΅ записи страницы id=1 

    1 answer 1

    Following the example headings:

     // Π‘Π½Π°Ρ‡Π°Π»Π° ΠΏΠΎΠ»ΡƒΡ‡ΠΈΠΌ всС Ρ€ΡƒΠ±Ρ€ΠΈΠΊΠΈ $terms = get_terms( 'category', array( 'hide_empty' => false, ) ); foreach ($terms as $term) { // Π’Ρ‹Π²Π΅Π΄Π΅ΠΌ ссылки Π½Π° Π½ΠΈΡ… echo '<a href="' . esc_url( get_term_link($term) ) . '">' . $term->name . '</a>'; // Под ΠΊΠ°ΠΆΠ΄ΠΎΠΉ Ρ€ΡƒΠ±Ρ€ΠΈΠΊΠΎΠΉ Π²Ρ‹Π²Π΅Π΄Π΅ΠΌ Ρ†ΠΈΠΊΠ» с Π΅Π΅ записями $cat_posts = new WP_Query(array('cat' => $term->term_id )); while($cat_posts->have_posts()) { $cat_posts->the_post(); echo '<a href="' . get_the_permalink() . '">'. get_the_title() .'</a>'; } } 

    I'm not sure that there are absolutely no bugs here, it’s not completely clear how WordPress behaves when 1 entry is in several headings at once ... In this case, it appears a cycle 2 times if there is one, you need to add checks, etc.

    • Well, actually, I have the task of displaying a site map based on the menu , and you display all the categories that may not be in the menu. - Yury Kovalev
    • take a function from here, output sub-cycles with entries based on the id existing in the developer.wordpress.org/reference/functions/wp_nav_menu menu - user3193246