php 儿童页面链接菜单

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 儿童页面链接菜单相关的知识,希望对你有一定的参考价值。

<!--
  ### get_pages() and wp_list_pages() are similar.
  ### get_pages() -This will returns the ages in memery.
  ### wp_list_pages() - This function will handle outputting the pages ont the screen for you.
  -->
<?php
  // If the current page has children this function will return a collection of any all children pages.
  // and if the current page doesn't have any children this function won't return anything. It will retun NULL, FALSE or 0.
 \!h $testArray = get_pages( array(
    'child_of' => get_the_ID()
    ) );
?>

<!--
### Only display side menu items only if you're currently on a child page
### On a child page, $theParent will returns a number of 0 // TRUE
### Also show if on parent page. $testArray
-->
\!h <?php if( $theParent || $testArray) : ?>
  <div class="page-links">
    <h2 class="page-links__title">
      <a href="<?php echo get_permalink( $theParent ) ?>"><?php echo get_the_title( $theParent ); ?></a>
    </h2>

    <ul class="min-list">
      <?php
        $theParent = wp_get_post_parent_id( get_the_ID() );
        if( $theParent ) {
          $findChildrenOf = $theParent;
        }else {
          $findChildrenOf = get_the_ID();
        }
      ?>
      <?php wp_list_pages(
        array(
            'title_li'    => '', // Get get of 'pages' text output
            'child_of'    => $findChildrenOf, // link to only children of the page
            'sort_column' => 'menu_order' // sort by menu order
        )
      ) ?>
    </ul>
  </div>
  <?php endif; ?>

以上是关于php 儿童页面链接菜单的主要内容,如果未能解决你的问题,请参考以下文章

如何给我的 WordPress 菜单页面自定义链接

PHP:如何根据用户/组验证对菜单中选项的访问?

javascript 计数菜单儿童

如何使用 php 和 HTML 更改活动链接的类名

PHP+ajax实现二级联动菜单功能

尝试通过单击另一个页面上的链接来访问页面上的部分时出错