WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Menu 'Seperator' (10 posts)

  1. toutski
    Member
    Posted 3 years ago #

    I've tried searching around for this and I hope its something simple.

    Can I have a menu link (page) that doesn't link to anything ie, is just a menu heading or separator?

    I want to have a menu option example 'Case Studies' that I don't want to link to anywhere, but below this option I want to have each case study as a menu option, that links to its own page.

    I hope this makes sense and any tips would be greatly appreciated.

  2. keesiemeijer
    moderator
    Posted 3 years ago #

    Do you mean a page with all post (or Page) titles (not in a link) or a menu with a Title of 'Case Studies'.

    <ul>
      <?php wp_list_pages('include=5,9,23&title_li=<h2>' . __('Case Studies') . '</h2>' ); ?>
    </ul>

    include the page ID's you want to include in the menu

  3. toutski
    Member
    Posted 3 years ago #

    I think the term I'm looking for is 'parent item with no link target'.

    I basically want to add an option into a menu but not have it link anywhere, just use it as a parent item for other child entries.

  4. keesiemeijer
    moderator
    Posted 3 years ago #

    Put this in your functions.php:

    function my_pages() {
      $mypages = get_pages();
      $html = '';
      if(!empty($mypages)) {
        foreach($mypages as $page) {
          if($page->post_parent == 0) {
          $html .= '<li><h2>' . $page->post_title . '</h2>' ."\n";
          $childpages = get_pages('child_of=' . $page->ID);
            if(!empty($childpages)) {
            $html .= '<ul class="children">'."\n";
              foreach($childpages as $cpage) {
    	    $html .= '<li><a href="' .get_page_link($cpage->ID) . '" ';
    	    $html .=  'title="' . $cpage->post_title . '">';
    	    $html .=  $cpage->post_title . '</a></li>'."\n";
    	  }
            $html .= '</ul>'."\n";
            }
          $html .= '</li>'."\n";
          }
        }
      }
    return $html;
    }

    And call the function in your template files like this:

    <ul>
      <?php echo my_pages(); ?>
    </ul>

    Then you get a list with all your Pages and the Parent Pages not in a link

  5. keesiemeijer
    moderator
    Posted 3 years ago #

    I simplified the function a bit:

    function my_pages() {
       $mypages = get_pages('parent=0');
       $html = '';
         if(!empty($mypages)) {
           foreach($mypages as $page) {
           $html .= '<li><h2>' . $page->post_title . '</h2>' ."\n";
           $childpages = get_pages('child_of=' . $page->ID);
             if(!empty($childpages)) {
    	 $html .= '<ul>';
    	 $html .= wp_list_pages("title_li=&child_of=".$page->ID."&echo=0");
    	 $html .= '</ul>';
             }
           $html .= '</li>'."\n";
           }
         }
     return $html;
    }
  6. toutski
    Member
    Posted 3 years ago #

    Many thanks for your response.

    Will this work for the main menu across the top of my site?

  7. keesiemeijer
    moderator
    Posted 3 years ago #

    I don't know what theme you use so I don't know. If your theme uses wp_list_pages() or if you use widgets or if it uses some other way (a function) of showing the top menu of pages. If it uses wp_list_pages() (most usual) you have to do a search in your theme template files for something simular to:

    <ul>
    <?php wp_list_pages(); ?>
    </ul>

    and replace it with:

    <ul>
      <?php echo my_pages(); ?>
    </ul>

    Can you give the link to the site or the link to the theme?

  8. toutski
    Member
    Posted 3 years ago #

    Thanks.

    I have found a nice plugin that does loads of cool things as well as what I want to achieve.

    http://wordpress.org/extend/plugins/page-lists-plus/

    Many thanks for you help keesiemeijer.

    Much appreciated.

  9. keesiemeijer
    moderator
    Posted 3 years ago #

    Glad you found a solution! Now, please use the dropdown at top right to mark this topic 'Resolved'.

  10. toutski
    Member
    Posted 3 years ago #

    Done! Thanks again.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.