Wordpress 高级自定义字段菜单

Wordpress Advanced Custom Fields menu

我使用 Advanced Custom 在 WordPress 站点开发了一个菜单 Fields.It 适用于它的主页而不适用于其他页面。例如当网站指向它的搜索页面时,菜单 disappears.Need 它出现在网站的每个页面上。

菜单代码如下

             <div id="main-menu" class="menu-list">

                <?php if( have_rows('header_links') ): ?>

                  <ul class="list-inline m-menu-ul">

                  <?php while( have_rows('header_links') ): the_row(); 

                    // vars
                    $menu_title = get_sub_field('menu_title');
                    $menu_link = get_sub_field('menu_link');

                    ?>

                    <li class="">

                      <?php if( $menu_link ): ?>
                        <a href="<?php echo $menu_link; ?>">
                      <?php endif; ?>

                        <?php echo $menu_title; ?>

                      <?php if( $menu_link ): ?>
                        </a>
                      <?php endif; ?>

                    </li>

                  <?php endwhile; ?>

                  </ul>

                <?php endif; ?>

              </div>

谢谢

您似乎只为主页定义了自定义字段 "header_links"。如果您想在所有页面中显示菜单,那么您可以将主页 ID 作为第二个参数传递给 have_rows,如下所示:

$page = get_page_by_title( 'Home' );
$home_id = $page->ID;
if(have_rows('header_links',$home_id)):
while( have_rows('header_links',$home_id) ): the_row($home_id);